mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-29 12:45:28 -05:00
Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b25c1250e5 | ||
|
|
98f3f51ba9 | ||
|
|
f0df9ead3c | ||
|
|
7b1a57070d | ||
|
|
a412f2fd5e | ||
|
|
4f0c8c4ab5 | ||
|
|
946c90a749 | ||
|
|
7ba4eaab9c | ||
|
|
74553a82fc | ||
|
|
39fcb2d743 | ||
|
|
7041feaea3 | ||
|
|
9b1ffaeded | ||
|
|
07d397bdac | ||
|
|
a86ff4f1f0 | ||
|
|
953eca2732 | ||
|
|
d6c5fb149a | ||
|
|
12982708cf | ||
|
|
0cf9e1dd81 | ||
|
|
71e20c4983 | ||
|
|
2147f6d3bf | ||
|
|
23df42d2d3 | ||
|
|
bcf0a0b7fd | ||
|
|
dd78b03a28 | ||
|
|
84dd5e6930 | ||
|
|
dcee98fea7 | ||
|
|
9ffb982ae5 | ||
|
|
428850306f | ||
|
|
abfd6798e3 | ||
|
|
fffadd94de | ||
|
|
d0919776f3 | ||
|
|
267855fded | ||
|
|
4bdebb7feb | ||
|
|
ab5f69d2ef | ||
|
|
63ee36ddfe | ||
|
|
43967f5ded | ||
|
|
c043053b2b | ||
|
|
220f27bd0a | ||
|
|
83914d5378 | ||
|
|
57e4b1a3f1 | ||
|
|
c85e556924 | ||
|
|
8c0be8011d | ||
|
|
7914f75876 | ||
|
|
7d1253e14e | ||
|
|
d7c58b3eb3 | ||
|
|
fb664b6f08 | ||
|
|
258a6d076e | ||
|
|
32ab060153 | ||
|
|
91d3784f9b | ||
|
|
8a5aac3d31 | ||
|
|
06c6effb7d | ||
|
|
f3789c05bd | ||
|
|
c64e1f5e51 | ||
|
|
5d8e24c19a | ||
|
|
f756de05c3 | ||
|
|
574fdb496f | ||
|
|
5580da69eb | ||
|
|
35274863c9 | ||
|
|
1f31b81f0d | ||
|
|
cde111ddeb | ||
|
|
845c12c01c | ||
|
|
99a0118d31 |
5
.github/scripts/.Aptfile
vendored
5
.github/scripts/.Aptfile
vendored
@@ -7,3 +7,8 @@ package 'ninja-build', bin: 'ninja'
|
||||
package 'pkg-config'
|
||||
package 'clang'
|
||||
package 'clang-format-13'
|
||||
package 'libxtst-dev'
|
||||
package 'libxss-dev'
|
||||
package 'libopencv-dev'
|
||||
package 'libtesseract-dev'
|
||||
package 'libprocps-dev'
|
||||
|
||||
7
.github/scripts/utils.zsh/setup_linux
vendored
7
.github/scripts/utils.zsh/setup_linux
vendored
@@ -34,13 +34,6 @@ if (( ! (${skips[(Ie)all]} + ${skips[(Ie)deps]}) )) {
|
||||
|
||||
log_info 'Installing obs plugin dependencies...'
|
||||
|
||||
sudo apt-get install -y \
|
||||
libxtst-dev \
|
||||
libxss-dev \
|
||||
libopencv-dev \
|
||||
libtesseract-dev \
|
||||
libprocps-dev
|
||||
|
||||
local -a _qt_packages=()
|
||||
|
||||
if (( QT_VERSION == 5 )) {
|
||||
|
||||
@@ -93,8 +93,12 @@ target_sources(
|
||||
${LIB_NAME}
|
||||
PRIVATE src/macro-core/macro-action-audio.cpp
|
||||
src/macro-core/macro-action-audio.hpp
|
||||
src/macro-core/macro-action-clipboard.cpp
|
||||
src/macro-core/macro-action-clipboard.hpp
|
||||
src/macro-core/macro-action-edit.cpp
|
||||
src/macro-core/macro-action-edit.hpp
|
||||
src/macro-core/macro-action-factory.cpp
|
||||
src/macro-core/macro-action-factory.hpp
|
||||
src/macro-core/macro-action-file.cpp
|
||||
src/macro-core/macro-action-file.hpp
|
||||
src/macro-core/macro-action-filter.cpp
|
||||
@@ -171,6 +175,8 @@ target_sources(
|
||||
src/macro-core/macro-condition-display.hpp
|
||||
src/macro-core/macro-condition-edit.cpp
|
||||
src/macro-core/macro-condition-edit.hpp
|
||||
src/macro-core/macro-condition-factory.cpp
|
||||
src/macro-core/macro-condition-factory.hpp
|
||||
src/macro-core/macro-condition-file.cpp
|
||||
src/macro-core/macro-condition-file.hpp
|
||||
src/macro-core/macro-condition-filter.cpp
|
||||
@@ -231,6 +237,8 @@ target_sources(
|
||||
src/macro-core/macro-condition.hpp
|
||||
src/macro-core/macro-dock.cpp
|
||||
src/macro-core/macro-dock.hpp
|
||||
src/macro-core/macro-helpers.cpp
|
||||
src/macro-core/macro-helpers.hpp
|
||||
src/macro-core/macro-properties.cpp
|
||||
src/macro-core/macro-properties.hpp
|
||||
src/macro-core/macro-ref.cpp
|
||||
@@ -254,6 +262,8 @@ target_sources(
|
||||
src/utils/connection-manager.hpp
|
||||
src/utils/curl-helper.cpp
|
||||
src/utils/curl-helper.hpp
|
||||
src/utils/duration.cpp
|
||||
src/utils/duration.hpp
|
||||
src/utils/duration-control.cpp
|
||||
src/utils/duration-control.hpp
|
||||
src/utils/export-symbol-helper.hpp
|
||||
@@ -287,6 +297,8 @@ target_sources(
|
||||
src/utils/obs-module-helper.hpp
|
||||
src/utils/osc-helpers.cpp
|
||||
src/utils/osc-helpers.hpp
|
||||
src/utils/plugin-state-helpers.cpp
|
||||
src/utils/plugin-state-helpers.hpp
|
||||
src/utils/priority-helper.cpp
|
||||
src/utils/priority-helper.hpp
|
||||
src/utils/process-config.cpp
|
||||
@@ -317,8 +329,8 @@ target_sources(
|
||||
src/utils/striped-frame.hpp
|
||||
src/utils/switch-button.cpp
|
||||
src/utils/switch-button.hpp
|
||||
src/utils/sync-helper.cpp
|
||||
src/utils/sync-helper.hpp
|
||||
src/utils/sync-helpers.cpp
|
||||
src/utils/sync-helpers.hpp
|
||||
src/utils/temp-variable.cpp
|
||||
src/utils/temp-variable.hpp
|
||||
src/utils/transition-selection.cpp
|
||||
@@ -458,27 +470,24 @@ else()
|
||||
|
||||
find_path(PROCPS_INCLUDE_DIR NAMES proc/procps.h)
|
||||
find_path(PROCPS2_INCLUDE_DIR NAMES libproc2/pids.h)
|
||||
find_library(PROCPS_LIBRARY NAMES procps)
|
||||
find_library(PROCPS2_LIBRARY NAMES proc2)
|
||||
if(PROCPS_INCLUDE_DIR AND PROCPS_LIBRARY)
|
||||
if(PROCPS_INCLUDE_DIR)
|
||||
message(STATUS "${PROJECT_NAME} using procps")
|
||||
set(PROC_INCLUDE_DIR "${PROCPS_INCLUDE_DIR}")
|
||||
set(PROC_LIBRARY "${PROCPS_LIBRARY}")
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE USE_PROCPS)
|
||||
elseif(PROCPS2_INCLUDE_DIR AND PROCPS2_LIBRARY)
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE PROCPS_AVAILABLE)
|
||||
set(PROCESS_CONDITION_SUPPORTED 1)
|
||||
endif()
|
||||
if(PROCPS2_INCLUDE_DIR)
|
||||
message(STATUS "${PROJECT_NAME} using libproc2")
|
||||
set(PROC_INCLUDE_DIR "${PROCPS2_INCLUDE_DIR}")
|
||||
set(PROC_LIBRARY "${PROCPS2_LIBRARY}")
|
||||
else()
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"found neither procps nor libproc2!
|
||||
please either set ...
|
||||
PROCPS_INCLUDE_DIR and PROCPS_LIBRARY
|
||||
... or ...
|
||||
PROCPS2_INCLUDE_DIR and PROCPS2_LIBRARY")
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE PROCPS2_AVAILABLE)
|
||||
set(PROCESS_CONDITION_SUPPORTED 1)
|
||||
endif()
|
||||
if(NOT DEFINED PROCESS_CONDITION_SUPPORTED)
|
||||
message(
|
||||
WARNING
|
||||
"found neither procps nor libproc2! Process condition will not be functional!"
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(${LIB_NAME} PRIVATE "${PROC_LIBRARY}")
|
||||
target_include_directories(${LIB_NAME} PRIVATE "${PROC_INCLUDE_DIR}")
|
||||
|
||||
find_package(CURL)
|
||||
|
||||
@@ -159,7 +159,6 @@ AdvSceneSwitcher.condition.media="Medien"
|
||||
AdvSceneSwitcher.condition.media.source="Quelle"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="Beliebige Medienquelle in"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="Alle Medienquellen in"
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="Nur bei Änderung übereinstimmen (Hinweis: Diese Option wird in einer zukünftigen Version entfernt werden - bitte stattdessen Dauer-Modifikatoren verwenden)"
|
||||
AdvSceneSwitcher.condition.media.inconsistencyInfo="Leider verhalten sich nicht alle Medien-Quell-Typen gleich (z.B. Medien-Quelle vs. VLC-Video-Quelle \"Gestoppt\"-Status).\nBitte experimentieren, was in eurem Setup funktioniert!"
|
||||
AdvSceneSwitcher.condition.media.entry="{{sourceTypes}}{{mediaSources}}{{scenes}}Status ist{{states}}und{{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="Video"
|
||||
@@ -221,9 +220,8 @@ AdvSceneSwitcher.condition.record="Aufnahme"
|
||||
AdvSceneSwitcher.condition.record.state.start="Aufnahme läuft"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Aufnahme pausiert"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Aufnahme gestoppt"
|
||||
AdvSceneSwitcher.condition.record.entry="{{recordState}}"
|
||||
AdvSceneSwitcher.condition.process="Prozess"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}} läuft {{focused}} und ist fokusiert"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}läuft{{focused}}und ist fokusiert"
|
||||
AdvSceneSwitcher.condition.process.entry.focus="Aktueller Vordergrundprozess: {{focusProcess}}"
|
||||
AdvSceneSwitcher.condition.idle="Leerlauf"
|
||||
AdvSceneSwitcher.condition.idle.entry="Keine Tastatur- oder Mauseingaben für {{duration}}"
|
||||
@@ -575,7 +573,6 @@ AdvSceneSwitcher.action.variable.invalidSelection="Ungültige Auswahl!"
|
||||
AdvSceneSwitcher.action.variable.actionNoVariableSupport="Das Abrufen von Variablenwerten aus %1 Aktionen wird nicht unterstützt!"
|
||||
AdvSceneSwitcher.action.variable.conditionNoVariableSupport="Das Abrufen von Variablenwerten aus %1 Bedingungen wird nicht unterstützt!"
|
||||
AdvSceneSwitcher.action.variable.currentSegmentValue="Aktueller Wert:"
|
||||
AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}"
|
||||
|
||||
|
||||
; Transition Tab
|
||||
|
||||
@@ -79,6 +79,7 @@ AdvSceneSwitcher.macroTab.edit.action="Action type:"
|
||||
AdvSceneSwitcher.macroTab.add="Add new macro"
|
||||
AdvSceneSwitcher.macroTab.name="Name:"
|
||||
AdvSceneSwitcher.macroTab.run="Run macro"
|
||||
AdvSceneSwitcher.macroTab.run.tooltip="Run all macro actions regardless of condition.\nIf else actions are available, hold Shift and click the button to execute them instead."
|
||||
AdvSceneSwitcher.macroTab.runElse="Run macro (else)"
|
||||
AdvSceneSwitcher.macroTab.runFail="Running \"%1\" failed!\nEither one of the actions failed or the macro is running already."
|
||||
AdvSceneSwitcher.macroTab.runInParallel="Run macro in parallel to other macros"
|
||||
@@ -125,6 +126,8 @@ AdvSceneSwitcher.macroTab.currentDockButtonText.unpause="Unpause button text:"
|
||||
AdvSceneSwitcher.macroTab.currentDockStatusText.true="Conditions true text:"
|
||||
AdvSceneSwitcher.macroTab.currentDockStatusText.false="Conditions false text:"
|
||||
AdvSceneSwitcher.macroTab.currentDockHighlightIfExecuted="Highlight dock if macro actions were recently executed"
|
||||
AdvSceneSwitcher.macroTab.toggleElseActions.hide.tooltip="Hide else actions"
|
||||
AdvSceneSwitcher.macroTab.toggleElseActions.show.tooltip="Show else actions"
|
||||
|
||||
AdvSceneSwitcher.macroDock.pause="Pause"
|
||||
AdvSceneSwitcher.macroDock.unpause="Unpause"
|
||||
@@ -204,7 +207,6 @@ AdvSceneSwitcher.condition.media="Media"
|
||||
AdvSceneSwitcher.condition.media.source="Source"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="Any media source on"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="All media sources on"
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="Only match on change (Note: This option will be removed in a future version - please use duration modifiers instead)"
|
||||
AdvSceneSwitcher.condition.media.inconsistencyInfo="Unfortunately not all media source types behave the same (e.g. Media Source vs. VLC Video Source \"Stopped\" state).\nSo please experiment what works for your setup!"
|
||||
AdvSceneSwitcher.condition.media.entry="{{sourceTypes}}{{mediaSources}}{{scenes}}state is{{states}}and{{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="Video"
|
||||
@@ -295,9 +297,10 @@ AdvSceneSwitcher.condition.record="Recording"
|
||||
AdvSceneSwitcher.condition.record.state.start="Recording running"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Recording paused"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Recording stopped"
|
||||
AdvSceneSwitcher.condition.record.entry="{{recordState}}"
|
||||
AdvSceneSwitcher.condition.record.state.duration="Recording duration is longer than"
|
||||
AdvSceneSwitcher.condition.record.entry="{{condition}}{{duration}}"
|
||||
AdvSceneSwitcher.condition.process="Process"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}is running{{focused}}and is focused"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}is running{{focused}}and is focused"
|
||||
AdvSceneSwitcher.condition.process.entry.focus="Current foreground process:{{focusProcess}}"
|
||||
AdvSceneSwitcher.condition.idle="Idle"
|
||||
AdvSceneSwitcher.condition.idle.entry="No keyboard or mouse inputs for{{duration}}"
|
||||
@@ -326,6 +329,7 @@ AdvSceneSwitcher.condition.macro.type.state="Macro condition state"
|
||||
AdvSceneSwitcher.condition.macro.type.multiState="Multiple macro condition state"
|
||||
AdvSceneSwitcher.condition.macro.type.actionDisabled="Macro action disabled"
|
||||
AdvSceneSwitcher.condition.macro.type.actionEnabled="Macro action enabled"
|
||||
AdvSceneSwitcher.condition.macro.type.paused="Macro is paused"
|
||||
AdvSceneSwitcher.condition.macro.type.selection="{{types}}"
|
||||
AdvSceneSwitcher.condition.macro.count.type.below="Less than"
|
||||
AdvSceneSwitcher.condition.macro.count.type.above="More than"
|
||||
@@ -341,6 +345,7 @@ AdvSceneSwitcher.condition.macro.count.entry.line1="{{macros}}was executed{{cond
|
||||
AdvSceneSwitcher.condition.macro.count.entry.line2="Current count:{{currentCount}}{{resetCount}}"
|
||||
AdvSceneSwitcher.condition.macro.actionState.disabled.entry="Action{{actionIndex}}of{{macros}}is disabled"
|
||||
AdvSceneSwitcher.condition.macro.actionState.enabled.entry="Action{{actionIndex}}of{{macros}}is enabled"
|
||||
AdvSceneSwitcher.condition.macro.paused.entry="Macro{{macros}}is paused"
|
||||
AdvSceneSwitcher.condition.source="Source"
|
||||
AdvSceneSwitcher.condition.source.type.active="Is active"
|
||||
AdvSceneSwitcher.condition.source.type.showing="Is showing"
|
||||
@@ -604,6 +609,7 @@ AdvSceneSwitcher.action.streaming.type.username="Set username"
|
||||
AdvSceneSwitcher.action.streaming.type.password="Set password"
|
||||
AdvSceneSwitcher.action.streaming.entry="{{actions}}{{keyFrameInterval}}{{stringValue}}{{showPassword}}"
|
||||
AdvSceneSwitcher.action.run="Run"
|
||||
AdvSceneSwitcher.action.run.entry.wait="{{wait}}Wait for process exit or at most {{timeout}}"
|
||||
AdvSceneSwitcher.action.sceneVisibility="Scene item visibility"
|
||||
AdvSceneSwitcher.action.sceneVisibility.type.show="Show"
|
||||
AdvSceneSwitcher.action.sceneVisibility.type.hide="Hide"
|
||||
@@ -814,6 +820,7 @@ AdvSceneSwitcher.action.variable.type.sceneItemCount="Set to scene item count of
|
||||
AdvSceneSwitcher.action.variable.type.stringLength="Set to length of string"
|
||||
AdvSceneSwitcher.action.variable.type.extractJson="Extract json field with name"
|
||||
AdvSceneSwitcher.action.variable.type.setToTempvar="Set to macro property"
|
||||
AdvSceneSwitcher.action.variable.type.sceneItemName="Set to scene item name at index"
|
||||
AdvSceneSwitcher.action.variable.askForValuePromptDefault="Assign value to variable \"%1\":"
|
||||
AdvSceneSwitcher.action.variable.askForValuePrompt="Assign value to variable:"
|
||||
AdvSceneSwitcher.action.variable.mathExpression.example="( 1 + 2 * 3 ) / 4"
|
||||
@@ -825,7 +832,7 @@ AdvSceneSwitcher.action.variable.invalidSelection="Invalid selection!"
|
||||
AdvSceneSwitcher.action.variable.actionNoVariableSupport="Getting variable values from %1 actions is not supported!"
|
||||
AdvSceneSwitcher.action.variable.conditionNoVariableSupport="Getting variable values from %1 conditions is not supported!"
|
||||
AdvSceneSwitcher.action.variable.currentSegmentValue="Current value:"
|
||||
AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}"
|
||||
AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}{{sceneItemIndex}}"
|
||||
AdvSceneSwitcher.action.variable.entry.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}"
|
||||
AdvSceneSwitcher.action.variable.entry.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:"
|
||||
AdvSceneSwitcher.action.variable.entry.findAndReplace="{{findStr}}{{replaceStr}}"
|
||||
@@ -874,6 +881,12 @@ AdvSceneSwitcher.action.twitch.announcement.blue="Blue"
|
||||
AdvSceneSwitcher.action.twitch.announcement.green="Green"
|
||||
AdvSceneSwitcher.action.twitch.announcement.orange="Orange"
|
||||
AdvSceneSwitcher.action.twitch.announcement.purple="Purple"
|
||||
AdvSceneSwitcher.action.clipboard="Clipboard"
|
||||
AdvSceneSwitcher.action.clipboard.type.copy.text="Copy text"
|
||||
AdvSceneSwitcher.action.clipboard.type.copy.image="Copy image"
|
||||
AdvSceneSwitcher.action.clipboard.copy.text.text.placeholder="Enter text"
|
||||
AdvSceneSwitcher.action.clipboard.copy.image.url.placeholder="Enter direct image URL"
|
||||
AdvSceneSwitcher.action.clipboard.copy.image.url.tooltip="Currently supported formats: PNG, JPG/JPEG, BMP, GIF."
|
||||
|
||||
; Hotkey
|
||||
AdvSceneSwitcher.hotkey.startSwitcherHotkey="Start the Advanced Scene Switcher"
|
||||
@@ -1281,9 +1294,9 @@ AdvSceneSwitcher.tempVar.twitch.started_at.shoutoutReceived="Shoutout time"
|
||||
AdvSceneSwitcher.tempVar.twitch.started_at.shoutoutReceived.description="The UTC timestamp (in RFC3339 format) of when the moderator sent the Shoutout."
|
||||
|
||||
AdvSceneSwitcher.tempVar.twitch.id.reward="Reward id"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_id.reward="User id redeeming reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_login.reward="User login redeeming reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_name.reward="User login redeeming reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_id.reward="User id redeeming the reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_login.reward="User login redeeming the reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_name.reward="User name redeeming the reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.user_input.reward="User input for reward"
|
||||
AdvSceneSwitcher.tempVar.twitch.reward.reward="Reward Information"
|
||||
AdvSceneSwitcher.tempVar.twitch.reward.reward.description="Basic information about the reward that was redeemed, at the time it was redeemed."
|
||||
@@ -1442,6 +1455,11 @@ AdvSceneSwitcher.tempVar.audio.sync_offset="Source audio sync offset"
|
||||
AdvSceneSwitcher.tempVar.audio.monitor="Source audio monitor type"
|
||||
AdvSceneSwitcher.tempVar.audio.balance="Source audio balance"
|
||||
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.primary="Primary clipboard item MIME type"
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.primary.description="Highest priority MIME type of the current item stored in clipboard, if available."
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.all="All clipboard item MIME types"
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.all.description="All MIME types of the current item stored in clipboard separated with space, if available."
|
||||
|
||||
AdvSceneSwitcher.tempVar.scene.current="Current scene"
|
||||
AdvSceneSwitcher.tempVar.scene.previous="Previous scene"
|
||||
AdvSceneSwitcher.tempVar.scene.preview="Preview scene"
|
||||
@@ -1468,6 +1486,27 @@ AdvSceneSwitcher.tempVar.midi.note="Note"
|
||||
AdvSceneSwitcher.tempVar.midi.value1="Value 1"
|
||||
AdvSceneSwitcher.tempVar.midi.value2="Value 2"
|
||||
|
||||
AdvSceneSwitcher.tempVar.macro.runCount="Run count"
|
||||
AdvSceneSwitcher.tempVar.macro.runCount.description="The number of times a macro was executed."
|
||||
AdvSceneSwitcher.tempVar.macro.matchedCount="Matched count"
|
||||
AdvSceneSwitcher.tempVar.macro.matchedCount.description="The number of macros of which the condition state was true."
|
||||
|
||||
AdvSceneSwitcher.tempVar.process.name="Process name"
|
||||
|
||||
AdvSceneSwitcher.tempVar.recording.durationSeconds="Recording duration"
|
||||
AdvSceneSwitcher.tempVar.recording.durationSeconds.description="Recording duration in seconds.\nThis value does not change while the recording is paused and will be reset to zero if the recording is stopped."
|
||||
|
||||
AdvSceneSwitcher.tempVar.video.patternCount="Pattern count"
|
||||
AdvSceneSwitcher.tempVar.video.patternCount.description="The number of times the given pattern has been found in a given video input frame."
|
||||
AdvSceneSwitcher.tempVar.video.objectCount="Object count"
|
||||
AdvSceneSwitcher.tempVar.video.objectCount.description="The number of objects the given model has identified in a given video input frame."
|
||||
AdvSceneSwitcher.tempVar.video.brightness="Average brightness"
|
||||
AdvSceneSwitcher.tempVar.video.brightness.description="The average brightness in a given video input frame in a range from 0 to 1 (dark to bright)."
|
||||
AdvSceneSwitcher.tempVar.video.text="OCR text"
|
||||
AdvSceneSwitcher.tempVar.video.text.description="The text detected in a given video input frame."
|
||||
AdvSceneSwitcher.tempVar.video.color="Average color"
|
||||
AdvSceneSwitcher.tempVar.video.color.description="The average RGB color in a given video input frame in HexArgb format."
|
||||
|
||||
AdvSceneSwitcher.selectScene="--select scene--"
|
||||
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
|
||||
AdvSceneSwitcher.selectCurrentScene="Current Scene"
|
||||
|
||||
@@ -129,7 +129,6 @@ AdvSceneSwitcher.condition.file.entry.line3="{{checkModificationDate}}{{checkFil
|
||||
AdvSceneSwitcher.condition.media="Medios"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="Cualquier fuente multimedia activada"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="Todas las fuentes de medios activadas"
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="Solo coincidir con el cambio (Nota: esta opción se eliminará en una versión futura; use modificadores de duración en su lugar)"
|
||||
AdvSceneSwitcher.condition.media.inconsistencyInfo="Desafortunadamente, no todos los tipos de fuentes de medios se comportan de la misma manera (p. ej., fuente de medios frente a estado \"Detenido\" de fuente de video VLC).\n¡Así que experimente lo que funciona para su configuración!"
|
||||
AdvSceneSwitcher.condition.media.entry="El estado de{{sourceTypes}}{{mediaSources}}{{scenes}}es{{states}}y{{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="Video"
|
||||
@@ -182,9 +181,8 @@ AdvSceneSwitcher.condition.record="Grabación"
|
||||
AdvSceneSwitcher.condition.record.state.start="Grabación en ejecución"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Grabación en pausa"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Grabación detenida"
|
||||
AdvSceneSwitcher.condition.record.entry="{{recordState}}"
|
||||
AdvSceneSwitcher.condition.process="Proceso"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}} se está ejecutando {{focused}} y está enfocado"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}se está ejecutando{{focused}}y está enfocado"
|
||||
AdvSceneSwitcher.condition.idle="Inactivo"
|
||||
AdvSceneSwitcher.condition.idle.entry="No hay entradas de teclado o ratón durante {{duration}}"
|
||||
AdvSceneSwitcher.condition.pluginState="Estado del complemento"
|
||||
|
||||
@@ -197,7 +197,6 @@ AdvSceneSwitcher.condition.media="Média"
|
||||
AdvSceneSwitcher.condition.media.source="Source"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="Toute source média sur la scène"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="Toutes les sources média sur la scène"
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="Ne correspondre qu'au changement (Remarque : Cette option sera supprimée dans une version future - veuillez plutôt utiliser les modificateurs de durée)"
|
||||
AdvSceneSwitcher.condition.media.inconsistencyInfo="Malheureusement, toutes les sources média ne se comportent pas de la même manière (par exemple, l'état \"Arrêté\" de la source Media par rapport à la source Vidéo VLC).\nPar conséquent, veuillez expérimenter ce qui fonctionne le mieux pour votre configuration !"
|
||||
AdvSceneSwitcher.condition.media.entry="{{sourceTypes}}{{mediaSources}}{{scenes}}l'état est{{states}}et{{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="Vidéo"
|
||||
@@ -286,7 +285,7 @@ AdvSceneSwitcher.condition.record.state.start="Enregistrement en cours"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Enregistrement en pause"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Arrêt de l'enregistrement"
|
||||
AdvSceneSwitcher.condition.process="Processus"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}en cours d'exécution{{focused}}et est au premier plan"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}en cours d'exécution{{focused}}et est au premier plan"
|
||||
AdvSceneSwitcher.condition.process.entry.focus="Processus au premier plan actuel :{{focusProcess}}"
|
||||
AdvSceneSwitcher.condition.idle="Inactif"
|
||||
AdvSceneSwitcher.condition.idle.entry="Aucune entrée de clavier ou de souris pendant{{duration}}"
|
||||
@@ -740,7 +739,6 @@ AdvSceneSwitcher.action.twitch.type.channel.info.title.set="Définir le titre du
|
||||
AdvSceneSwitcher.action.twitch.type.channel.info.category.set="Définir la catégorie du flux"
|
||||
AdvSceneSwitcher.action.twitch.type.commercial.start="Démarrer une publicité d'une durée de"
|
||||
AdvSceneSwitcher.action.twitch.categorySelectionDisabled="Impossible de sélectionner une catégorie sans avoir d'abord sélectionné un compte Twitch !"
|
||||
AdvSceneSwitcher.action.twitch.entry.line1="Sur{{account}}{{actions}}{{streamTitle}}{{category}}{{markerDescription}}{{clipHasDelay}}{{duration}}{{announcementColor}}{{channel}}"
|
||||
|
||||
; Transition Tab
|
||||
AdvSceneSwitcher.transitionTab.title="Transition"
|
||||
|
||||
@@ -107,7 +107,7 @@ AdvSceneSwitcher.condition.record.state.start="Запись запущена"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Запись приостановлена"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Запись остановлена"
|
||||
AdvSceneSwitcher.condition.process="Процесс"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}} запущен {{focused}} и сфокусирован"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}запущен{{focused}}и сфокусирован"
|
||||
AdvSceneSwitcher.condition.idle="Простой"
|
||||
AdvSceneSwitcher.condition.idle.entry="Не было ни клавиатуры, ни мыши в течении{{duration}}"
|
||||
AdvSceneSwitcher.condition.pluginState="Состояние плагина"
|
||||
|
||||
@@ -119,7 +119,6 @@ AdvSceneSwitcher.condition.file.entry.line3="{{checkModificationDate}}{{checkFil
|
||||
AdvSceneSwitcher.condition.media="Medya"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="Herhangi bir medya kaynağı"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="Tüm medya kaynakları "
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="Yalnızca değişiklikle eşleştirin (Not: Bu seçenek gelecekteki bir sürümde kaldırılacaktır - lütfen bunun yerine zaman kısıtlamalarını kullanın)"
|
||||
AdvSceneSwitcher.condition.media.entry="{{sourceTypes}}{{mediaSources}}{{scenes}}durumu{{states}}ve{{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="Video"
|
||||
AdvSceneSwitcher.condition.video.condition.match="Tam olarak eşleşir"
|
||||
@@ -159,9 +158,8 @@ AdvSceneSwitcher.condition.record="Kayıt"
|
||||
AdvSceneSwitcher.condition.record.state.start="Kayıt Çalışıyor"
|
||||
AdvSceneSwitcher.condition.record.state.pause="Kayıt durakladı"
|
||||
AdvSceneSwitcher.condition.record.state.stop="Kayıt durdu"
|
||||
AdvSceneSwitcher.condition.record.entry="{{recordState}}"
|
||||
AdvSceneSwitcher.condition.process="İşlem"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}} çalışıyor {{focused}} ve odaklandı"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}çalışıyor{{focused}}ve odaklandı"
|
||||
AdvSceneSwitcher.condition.idle="Boşta"
|
||||
AdvSceneSwitcher.condition.idle.entry="...için klavye veya fare girişi yok {{duration}}"
|
||||
AdvSceneSwitcher.condition.pluginState="Eklenti durumu"
|
||||
|
||||
@@ -185,7 +185,6 @@ AdvSceneSwitcher.condition.media="媒体"
|
||||
AdvSceneSwitcher.condition.media.source="源"
|
||||
AdvSceneSwitcher.condition.media.anyOnScene="任何媒体源"
|
||||
AdvSceneSwitcher.condition.media.allOnScene="所有媒体源"
|
||||
AdvSceneSwitcher.condition.media.matchOnChange="仅在更改时匹配(注意:此选项将在未来版本中删除-请改用时间限制)"
|
||||
AdvSceneSwitcher.condition.media.inconsistencyInfo="不幸的是,并非所有媒体源类型的行为都相同(例如,媒体源与VLC视频源“停止”状态)。\n所以,请尝试适合您的设置!"
|
||||
AdvSceneSwitcher.condition.media.entry="{{sourceTypes}}{{mediaSources}}{{scenes}} 的状态是 {{states}} 和 {{timeRestrictions}}{{time}}"
|
||||
AdvSceneSwitcher.condition.video="视频"
|
||||
@@ -267,9 +266,8 @@ AdvSceneSwitcher.condition.record="录制"
|
||||
AdvSceneSwitcher.condition.record.state.start="录制运行中"
|
||||
AdvSceneSwitcher.condition.record.state.pause="录制暂停"
|
||||
AdvSceneSwitcher.condition.record.state.stop="录制停止"
|
||||
AdvSceneSwitcher.condition.record.entry="{{recordState}}"
|
||||
AdvSceneSwitcher.condition.process="进程"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}} 是正在运行 {{focused}} 并且是获得焦点"
|
||||
AdvSceneSwitcher.condition.process.entry="{{processes}}{{regex}}是正在运行{{focused}}并且是获得焦点"
|
||||
AdvSceneSwitcher.condition.process.entry.focus="当前焦点进程: {{focusProcess}}"
|
||||
AdvSceneSwitcher.condition.idle="闲置检测"
|
||||
AdvSceneSwitcher.condition.idle.entry="没有键盘或鼠标输入{{duration}}"
|
||||
@@ -651,7 +649,6 @@ AdvSceneSwitcher.action.variable.invalidSelection="无效选择!"
|
||||
AdvSceneSwitcher.action.variable.actionNoVariableSupport="不支持从 %1 个操作获取变量值!"
|
||||
AdvSceneSwitcher.action.variable.conditionNoVariableSupport="不支持从 %1 条件中获取变量值!"
|
||||
AdvSceneSwitcher.action.variable.currentSegmentValue="当前值:"
|
||||
AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}"
|
||||
AdvSceneSwitcher.action.variable.entry.substringIndex="子字符串开始:{{subStringStart}} 子字符串大小:{{subStringSize}}"
|
||||
AdvSceneSwitcher.action.variable.entry.substringRegex="使用正则表达式为 {{regexMatchIdx}} 匹配的值:"
|
||||
AdvSceneSwitcher.action.variable.entry.findAndReplace="{{findStr}}{{replaceStr}}"
|
||||
|
||||
11
data/res/images/DarkNotEqual.svg
Normal file
11
data/res/images/DarkNotEqual.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" version="1.1">
|
||||
<!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit-->
|
||||
|
||||
<g class="layer">
|
||||
<title>Layer 1</title>
|
||||
<rect fill="#fefefe" height="2.25" id="svg_1" stroke="#fefefe" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="13" x="1.5" y="4"/>
|
||||
<rect fill="#fefefe" height="2.25" id="svg_2" stroke="#fefefe" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="13" x="1.5" y="10"/>
|
||||
<rect fill="#fefefe" height="1" id="svg_4" stroke="#fefefe" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(0.341951, -0.926734, 0.939718, 0.337226, -1.948, 13.2448)" width="14" x="1" y="7"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 931 B |
11
data/res/images/LightNotEqual.svg
Normal file
11
data/res/images/LightNotEqual.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" version="1.1">
|
||||
<!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit-->
|
||||
|
||||
<g class="layer">
|
||||
<title>Layer 1</title>
|
||||
<rect fill="#202020" height="2.25" id="svg_1" stroke="#202020" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="13" x="1.5" y="4"/>
|
||||
<rect fill="#202020" height="2.25" id="svg_2" stroke="#202020" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="13" x="1.5" y="10"/>
|
||||
<rect fill="#202020" height="1" id="svg_4" stroke="#202020" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(0.341951, -0.926734, 0.939718, 0.337226, -1.948, 13.2448)" width="14" x="1" y="7"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 931 B |
@@ -119,7 +119,7 @@
|
||||
<string notr="true">ms</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>50</number>
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20000</number>
|
||||
@@ -1275,6 +1275,22 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="toggleElseActions">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "status-control.hpp"
|
||||
#include "scene-switch-helpers.hpp"
|
||||
#include "curl-helper.hpp"
|
||||
@@ -10,6 +11,7 @@
|
||||
#include <QMainWindow>
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
#include <QDirIterator>
|
||||
#include <regex>
|
||||
#include <filesystem>
|
||||
@@ -115,10 +117,27 @@ void AdvSceneSwitcher::LoadUI()
|
||||
loading = false;
|
||||
}
|
||||
|
||||
bool AdvSceneSwitcher::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
auto eventType = event->type();
|
||||
if (obj == ui->macroElseActions && eventType == QEvent::Resize) {
|
||||
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
|
||||
|
||||
if (resizeEvent->size().height() == 0) {
|
||||
SetElseActionsStateToHidden();
|
||||
return QDialog::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
SetElseActionsStateToVisible();
|
||||
}
|
||||
|
||||
return QDialog::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Saving and loading
|
||||
******************************************************************************/
|
||||
static void AskForBackup(obs_data_t *obj);
|
||||
static void AskForBackup(const QString &json);
|
||||
|
||||
static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
|
||||
{
|
||||
@@ -139,16 +158,25 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
|
||||
switcher->Stop();
|
||||
|
||||
switcher->m.lock();
|
||||
obs_data_t *obj =
|
||||
OBSDataAutoRelease obj =
|
||||
obs_data_get_obj(save_data, "advanced-scene-switcher");
|
||||
if (!obj) {
|
||||
obj = obs_data_create();
|
||||
}
|
||||
if (switcher->VersionChanged(obj, g_GIT_SHA1)) {
|
||||
AskForBackup(obj);
|
||||
auto json = obs_data_get_json(obj);
|
||||
static QString jsonQString = json ? json : "";
|
||||
std::thread t([]() {
|
||||
obs_queue_task(
|
||||
OBS_TASK_UI,
|
||||
[](void *) {
|
||||
AskForBackup(jsonQString);
|
||||
},
|
||||
nullptr, false);
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
switcher->LoadSettings(obj);
|
||||
obs_data_release(obj);
|
||||
switcher->m.unlock();
|
||||
|
||||
if (!switcher->stop) {
|
||||
@@ -157,12 +185,12 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
|
||||
}
|
||||
}
|
||||
|
||||
static void AskForBackup(obs_data_t *obj)
|
||||
static void AskForBackup(const QString &json)
|
||||
{
|
||||
bool backupSettings = DisplayMessage(
|
||||
obs_module_text("AdvSceneSwitcher.askBackup"), true);
|
||||
const bool backupWasConfirmed = DisplayMessage(
|
||||
obs_module_text("AdvSceneSwitcher.askBackup"), true, false);
|
||||
|
||||
if (!backupSettings) {
|
||||
if (!backupWasConfirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -181,8 +209,8 @@ static void AskForBackup(obs_data_t *obj)
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs_data_save_json(obj, file.fileName().toUtf8().constData());
|
||||
auto out = QTextStream(&file);
|
||||
out << json;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -209,7 +237,6 @@ void SwitcherData::Thread()
|
||||
// if a longer transition is used than the configured check interval
|
||||
bool setPrevSceneAfterLinger = false;
|
||||
bool macroMatch = false;
|
||||
macroSceneSwitched = false;
|
||||
endTime = std::chrono::high_resolution_clock::now();
|
||||
auto runTime =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
@@ -320,22 +347,12 @@ void SwitcherData::SetPreconditions()
|
||||
// Process name
|
||||
GetForegroundProcessName(currentForegroundProcess);
|
||||
|
||||
// Cursor
|
||||
std::pair<int, int> cursorPos = GetCursorPos();
|
||||
cursorPosChanged = cursorPos.first != switcher->lastCursorPos.first ||
|
||||
cursorPos.second != switcher->lastCursorPos.second;
|
||||
lastCursorPos = GetCursorPos();
|
||||
|
||||
// Macro
|
||||
InvalidateMacroTempVarValues();
|
||||
}
|
||||
|
||||
void ClearWebsocketMessages();
|
||||
|
||||
void SwitcherData::ResetForNextInterval()
|
||||
{
|
||||
// Core reset functions
|
||||
ClearWebsocketMessages();
|
||||
// Plugin reset functions
|
||||
for (const auto &func : resetIntervalSteps) {
|
||||
func();
|
||||
@@ -411,7 +428,7 @@ bool SwitcherData::CheckForMatch(OBSWeakSource &scene,
|
||||
|
||||
static void ResetMacros()
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
for (auto &m : GetMacros()) {
|
||||
m->ResetRunCount();
|
||||
m->ResetTimers();
|
||||
}
|
||||
@@ -454,9 +471,9 @@ void SwitcherData::Stop()
|
||||
if (th && th->isRunning()) {
|
||||
stop = true;
|
||||
cv.notify_all();
|
||||
abortMacroWait = true;
|
||||
macroWaitCv.notify_all();
|
||||
macroTransitionCv.notify_all();
|
||||
SetMacroAbortWait(true);
|
||||
GetMacroWaitCV().notify_all();
|
||||
GetMacroTransitionCV().notify_all();
|
||||
|
||||
// Not waiting if a dialog was closed is a workaround to avoid
|
||||
// deadlocks when a variable input dialog is opened while Stop()
|
||||
@@ -529,9 +546,6 @@ extern "C" void FreeSceneSwitcher()
|
||||
|
||||
static void handleSceneChange()
|
||||
{
|
||||
switcher->lastSceneChangeTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Stop waiting if scene was changed
|
||||
if (switcher->SceneChangedDuringWait()) {
|
||||
switcher->cv.notify_one();
|
||||
@@ -598,28 +612,9 @@ static void handlePeviewSceneChange()
|
||||
}
|
||||
}
|
||||
|
||||
static void setReplayBufferSaved()
|
||||
static void handleTransitionEnd()
|
||||
{
|
||||
switcher->replayBufferSaved = true;
|
||||
}
|
||||
|
||||
static void setTranstionEnd()
|
||||
{
|
||||
switcher->lastTransitionEndTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
switcher->macroTransitionCv.notify_all();
|
||||
}
|
||||
|
||||
static void setStreamStarting()
|
||||
{
|
||||
switcher->lastStreamStartingTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
static void setStreamStopping()
|
||||
{
|
||||
switcher->lastStreamStoppingTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
GetMacroTransitionCV().notify_all();
|
||||
}
|
||||
|
||||
static void handleShutdown()
|
||||
@@ -628,10 +623,10 @@ static void handleShutdown()
|
||||
return;
|
||||
}
|
||||
switcher->obsIsShuttingDown = true;
|
||||
if (switcher->shutdownConditionCount) {
|
||||
if (ShutdownCheckIsNecessary()) {
|
||||
switcher->Stop();
|
||||
switcher->CheckMacros();
|
||||
switcher->RunMacros();
|
||||
CheckMacros();
|
||||
RunMacros();
|
||||
|
||||
// Unfortunately this will not work as OBS will now allow saving
|
||||
// the scene collection data at this point, So any OBS specific
|
||||
@@ -688,19 +683,8 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher)
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STOPPED:
|
||||
resetLiveTime();
|
||||
break;
|
||||
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(26, 0, 0)
|
||||
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED:
|
||||
setReplayBufferSaved();
|
||||
break;
|
||||
#endif
|
||||
case OBS_FRONTEND_EVENT_TRANSITION_STOPPED:
|
||||
setTranstionEnd();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STARTING:
|
||||
setStreamStarting();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STOPPING:
|
||||
setStreamStopping();
|
||||
handleTransitionEnd();
|
||||
break;
|
||||
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(27, 2, 0)
|
||||
case OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING:
|
||||
@@ -759,6 +743,9 @@ void OpenSettingsWindow()
|
||||
}
|
||||
}
|
||||
|
||||
void SetupConnectionManager();
|
||||
void SetupWebsocketHelpers();
|
||||
|
||||
extern "C" void InitSceneSwitcher(obs_module_t *module, translateFunc translate)
|
||||
{
|
||||
blog(LOG_INFO, "version: %s", g_GIT_TAG);
|
||||
@@ -769,6 +756,8 @@ extern "C" void InitSceneSwitcher(obs_module_t *module, translateFunc translate)
|
||||
PlatformInit();
|
||||
LoadPlugins();
|
||||
SetupDock();
|
||||
SetupConnectionManager();
|
||||
SetupWebsocketHelpers();
|
||||
|
||||
obs_frontend_add_save_callback(SaveSceneSwitcher, nullptr);
|
||||
obs_frontend_add_event_callback(OBSEvent, switcher);
|
||||
|
||||
@@ -39,6 +39,9 @@ public:
|
||||
void RestoreWindowGeo();
|
||||
void CheckFirstTimeSetup();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
/* --- Begin of general tab section --- */
|
||||
public:
|
||||
void SetupGeneralTab();
|
||||
@@ -115,6 +118,7 @@ public slots:
|
||||
void on_actionUp_clicked();
|
||||
void on_actionDown_clicked();
|
||||
void on_actionBottom_clicked();
|
||||
void on_toggleElseActions_clicked();
|
||||
void on_elseActionAdd_clicked();
|
||||
void on_elseActionRemove_clicked();
|
||||
void on_elseActionTop_clicked();
|
||||
@@ -146,6 +150,8 @@ public slots:
|
||||
void MaximizeElseActions();
|
||||
void MinimizeConditions();
|
||||
void MaximizeConditions();
|
||||
void SetElseActionsStateToHidden();
|
||||
void SetElseActionsStateToVisible();
|
||||
void MacroActionSelectionChanged(int idx);
|
||||
void MacroActionReorder(int to, int target);
|
||||
void AddMacroAction(int idx);
|
||||
@@ -334,7 +340,7 @@ public slots:
|
||||
void on_timeUp_clicked();
|
||||
void on_timeDown_clicked();
|
||||
|
||||
// Video tab
|
||||
// Audio tab
|
||||
public:
|
||||
void SetupAudioTab();
|
||||
public slots:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "status-control.hpp"
|
||||
#include "file-selection.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "version.h"
|
||||
|
||||
@@ -33,7 +34,7 @@ void AdvSceneSwitcher::on_noMatchDontSwitch_clicked()
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->switchIfNotMatching = SwitcherData::NoMatch::NO_SWITCH;
|
||||
switcher->switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
|
||||
ui->noMatchSwitchScene->setEnabled(false);
|
||||
ui->randomDisabledWarning->setVisible(true);
|
||||
}
|
||||
@@ -45,7 +46,7 @@ void AdvSceneSwitcher::on_noMatchSwitch_clicked()
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->switchIfNotMatching = SwitcherData::NoMatch::SWITCH;
|
||||
switcher->switchIfNotMatching = NoMatchBehavior::SWITCH;
|
||||
ui->noMatchSwitchScene->setEnabled(true);
|
||||
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
|
||||
ui->randomDisabledWarning->setVisible(true);
|
||||
@@ -58,7 +59,7 @@ void AdvSceneSwitcher::on_noMatchRandomSwitch_clicked()
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->switchIfNotMatching = SwitcherData::NoMatch::RANDOM_SWITCH;
|
||||
switcher->switchIfNotMatching = NoMatchBehavior::RANDOM_SWITCH;
|
||||
ui->noMatchSwitchScene->setEnabled(false);
|
||||
ui->randomDisabledWarning->setVisible(false);
|
||||
}
|
||||
@@ -506,13 +507,13 @@ void SwitcherData::LoadSettings(obs_data_t *obj)
|
||||
// selections to be available.
|
||||
loadSceneGroups(obj);
|
||||
LoadVariables(obj);
|
||||
LoadConnections(obj);
|
||||
|
||||
for (const auto &func : loadSteps) {
|
||||
func(obj);
|
||||
}
|
||||
|
||||
LoadMacros(obj);
|
||||
LoadGlobalMacroProperties(obj);
|
||||
loadWindowTitleSwitches(obj);
|
||||
loadScreenRegionSwitches(obj);
|
||||
loadPauseSwitches(obj);
|
||||
@@ -549,7 +550,7 @@ void SwitcherData::SaveSettings(obs_data_t *obj)
|
||||
|
||||
saveSceneGroups(obj);
|
||||
SaveMacros(obj);
|
||||
SaveConnections(obj);
|
||||
SaveGlobalMacroProperties(obj);
|
||||
SaveVariables(obj);
|
||||
saveWindowTitleSwitches(obj);
|
||||
saveScreenRegionSwitches(obj);
|
||||
@@ -624,9 +625,9 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj)
|
||||
interval = obs_data_get_int(obj, "interval");
|
||||
|
||||
obs_data_set_default_int(obj, "switch_if_not_matching",
|
||||
static_cast<int>(NoMatch::NO_SWITCH));
|
||||
switchIfNotMatching =
|
||||
(NoMatch)obs_data_get_int(obj, "switch_if_not_matching");
|
||||
static_cast<int>(NoMatchBehavior::NO_SWITCH));
|
||||
switchIfNotMatching = static_cast<NoMatchBehavior>(
|
||||
obs_data_get_int(obj, "switch_if_not_matching"));
|
||||
std::string nonMatchingSceneName =
|
||||
obs_data_get_string(obj, "non_matching_scene");
|
||||
nonMatchingScene = GetWeakSourceByName(nonMatchingSceneName.c_str());
|
||||
@@ -800,12 +801,13 @@ void SwitcherData::CheckNoMatchSwitch(bool &match, OBSWeakSource &scene,
|
||||
return;
|
||||
}
|
||||
|
||||
if (switchIfNotMatching == NoMatch::SWITCH && nonMatchingScene) {
|
||||
if (switchIfNotMatching == NoMatchBehavior::SWITCH &&
|
||||
nonMatchingScene) {
|
||||
match = true;
|
||||
scene = nonMatchingScene;
|
||||
transition = nullptr;
|
||||
}
|
||||
if (switchIfNotMatching == NoMatch::RANDOM_SWITCH) {
|
||||
if (switchIfNotMatching == NoMatchBehavior::RANDOM_SWITCH) {
|
||||
match = checkRandom(scene, transition, sleep);
|
||||
}
|
||||
}
|
||||
@@ -956,11 +958,11 @@ void AdvSceneSwitcher::SetupGeneralTab()
|
||||
{
|
||||
PopulateSceneSelection(ui->noMatchSwitchScene, false);
|
||||
|
||||
if (switcher->switchIfNotMatching == SwitcherData::NoMatch::SWITCH) {
|
||||
if (switcher->switchIfNotMatching == NoMatchBehavior::SWITCH) {
|
||||
ui->noMatchSwitch->setChecked(true);
|
||||
ui->noMatchSwitchScene->setEnabled(true);
|
||||
} else if (switcher->switchIfNotMatching ==
|
||||
SwitcherData::NoMatch::NO_SWITCH) {
|
||||
NoMatchBehavior::NO_SWITCH) {
|
||||
ui->noMatchDontSwitch->setChecked(true);
|
||||
ui->noMatchSwitchScene->setEnabled(false);
|
||||
} else {
|
||||
|
||||
@@ -160,7 +160,9 @@ enum class HotkeyType {
|
||||
Key_NumpadMultiply,
|
||||
Key_NumpadDivide,
|
||||
Key_NumpadDecimal,
|
||||
Key_NumpadEnter
|
||||
Key_NumpadEnter,
|
||||
|
||||
Key_Tilde,
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -12,6 +12,11 @@ namespace advss {
|
||||
static QMetaObject::Connection addPulse;
|
||||
SceneGroupEditWidget *typeEdit = nullptr;
|
||||
|
||||
std::deque<SceneGroup> &GetSceneGroups()
|
||||
{
|
||||
return switcher->sceneGroups;
|
||||
}
|
||||
|
||||
void SceneGroup::advanceIdx()
|
||||
{
|
||||
currentIdx++;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
@@ -87,5 +87,6 @@ private:
|
||||
|
||||
SceneGroup *GetSceneGroupByName(const char *name);
|
||||
SceneGroup *GetSceneGroupByQString(const QString &name);
|
||||
std::deque<SceneGroup> &GetSceneGroups();
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -177,17 +177,17 @@ static std::string getRemoteData(std::string &url)
|
||||
{
|
||||
std::string readBuffer;
|
||||
|
||||
switcher->curl.SetOpt(CURLOPT_URL, url.c_str());
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEDATA, &readBuffer);
|
||||
CurlHelper::SetOpt(CURLOPT_URL, url.c_str());
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEDATA, &readBuffer);
|
||||
|
||||
// Set timeout to at least one second
|
||||
int timeout = switcher->interval / 1000;
|
||||
if (timeout == 0) {
|
||||
timeout = 1;
|
||||
}
|
||||
switcher->curl.SetOpt(CURLOPT_TIMEOUT, 1);
|
||||
switcher->curl.Perform();
|
||||
CurlHelper::SetOpt(CURLOPT_TIMEOUT, 1);
|
||||
CurlHelper::Perform();
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
@@ -422,7 +422,7 @@ void AdvSceneSwitcher::SetupFileTab()
|
||||
obs_module_text("AdvSceneSwitcher.fileTab.remoteFileWarning2"));
|
||||
ui->remoteFileWarningLabel->hide();
|
||||
|
||||
if (switcher->curl.Initialized()) {
|
||||
if (CurlHelper::Initialized()) {
|
||||
ui->libcurlWarning->setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,8 +143,7 @@ void AdvSceneSwitcher::SetupRandomTab()
|
||||
border-radius: 7px; \
|
||||
border-color: rgb(0,0,0,0) \
|
||||
}");
|
||||
if (switcher->switchIfNotMatching !=
|
||||
SwitcherData::NoMatch::RANDOM_SWITCH) {
|
||||
if (switcher->switchIfNotMatching != NoMatchBehavior::RANDOM_SWITCH) {
|
||||
if (!switcher->disableHints) {
|
||||
PulseWidget(ui->randomDisabledWarning, QColor(Qt::red),
|
||||
QColor(0, 0, 0, 0));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "platform-funcs.hpp"
|
||||
#include "hotkey.hpp"
|
||||
#include "log-helper.hpp"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
@@ -25,9 +26,10 @@
|
||||
#include <QStringList>
|
||||
#include <QRegularExpression>
|
||||
#include <QLibrary>
|
||||
#ifdef USE_PROCPS
|
||||
#ifdef PROCPS_AVAILABLE
|
||||
#include <proc/readproc.h>
|
||||
#else
|
||||
#endif
|
||||
#ifdef PROCPS2_AVAILABLE
|
||||
#include <libproc2/pids.h>
|
||||
#endif
|
||||
#include <fstream>
|
||||
@@ -53,6 +55,31 @@ std::chrono::high_resolution_clock::time_point lastMouseLeftClickTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastMouseMiddleClickTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastMouseRightClickTime{};
|
||||
|
||||
static QLibrary *libprocps = nullptr;
|
||||
#ifdef PROCPS_AVAILABLE
|
||||
typedef PROCTAB *(*openproc_func)(int flags);
|
||||
typedef void (*closeproc_func)(PROCTAB *PT);
|
||||
typedef proc_t *(*readproc_func)(PROCTAB *__restrict const PT,
|
||||
proc_t *__restrict p);
|
||||
static openproc_func openproc_ = nullptr;
|
||||
static closeproc_func closeproc_ = nullptr;
|
||||
static readproc_func readproc_ = nullptr;
|
||||
#endif
|
||||
static bool libprocpsSupported = false;
|
||||
|
||||
static QLibrary *libproc2 = nullptr;
|
||||
#ifdef PROCPS2_AVAILABLE
|
||||
typedef int (*procps_pids_new_func)(struct pids_info **info,
|
||||
enum pids_item *items, int numitems);
|
||||
typedef struct pids_stack *(*procps_pids_get_func)(struct pids_info *info,
|
||||
enum pids_fetch_type which);
|
||||
typedef int (*procps_pids_unref_func)(struct pids_info **info);
|
||||
static procps_pids_new_func procps_pids_new_ = nullptr;
|
||||
static procps_pids_get_func procps_pids_get_ = nullptr;
|
||||
static procps_pids_unref_func procps_pids_unref_ = nullptr;
|
||||
#endif
|
||||
static bool libprocps2Supported = false;
|
||||
|
||||
Display *disp()
|
||||
{
|
||||
if (!xdisplay) {
|
||||
@@ -338,46 +365,57 @@ std::optional<std::string> GetTextInWindow(const std::string &)
|
||||
return {};
|
||||
}
|
||||
|
||||
#ifdef USE_PROCPS
|
||||
void GetProcessList(QStringList &processes)
|
||||
static void getProcessListProcps(QStringList &processes)
|
||||
{
|
||||
processes.clear();
|
||||
PROCTAB *proc = openproc(PROC_FILLSTAT);
|
||||
#ifdef PROCPS_AVAILABLE
|
||||
PROCTAB *proc = openproc_(PROC_FILLSTAT);
|
||||
proc_t proc_info;
|
||||
memset(&proc_info, 0, sizeof(proc_info));
|
||||
while (readproc(proc, &proc_info) != NULL) {
|
||||
while (readproc_(proc, &proc_info) != NULL) {
|
||||
QString procName(proc_info.cmd);
|
||||
if (!procName.isEmpty() && !processes.contains(procName)) {
|
||||
processes << procName;
|
||||
}
|
||||
}
|
||||
closeproc(proc);
|
||||
closeproc_(proc);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void GetProcessList(QStringList &processes)
|
||||
|
||||
static void getProcessListProcps2(QStringList &processes)
|
||||
{
|
||||
processes.clear();
|
||||
#ifdef PROCPS2_AVAILABLE
|
||||
struct pids_info *info = NULL;
|
||||
struct pids_stack *stack;
|
||||
enum pids_item Items[] = {
|
||||
PIDS_CMD,
|
||||
};
|
||||
|
||||
if (procps_pids_new(&info, Items, sizeof(Items) / sizeof(Items[0])) <
|
||||
if (procps_pids_new_(&info, Items, sizeof(Items) / sizeof(Items[0])) <
|
||||
0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) {
|
||||
while ((stack = procps_pids_get_(info, PIDS_FETCH_TASKS_ONLY))) {
|
||||
auto cmd = PIDS_VAL(0, str, stack, info);
|
||||
QString procName(cmd);
|
||||
if (!procName.isEmpty() && !processes.contains(procName)) {
|
||||
processes << procName;
|
||||
}
|
||||
}
|
||||
procps_pids_unref(&info);
|
||||
}
|
||||
procps_pids_unref_(&info);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GetProcessList(QStringList &processes)
|
||||
{
|
||||
processes.clear();
|
||||
if (libprocpsSupported) {
|
||||
getProcessListProcps(processes);
|
||||
return;
|
||||
}
|
||||
if (libprocps2Supported) {
|
||||
getProcessListProcps2(processes);
|
||||
}
|
||||
}
|
||||
|
||||
long getForegroundProcessPid()
|
||||
{
|
||||
@@ -517,6 +555,9 @@ static std::unordered_map<HotkeyType, long> keyTable = {
|
||||
{HotkeyType::Key_8, XK_8},
|
||||
{HotkeyType::Key_9, XK_9},
|
||||
|
||||
// Other
|
||||
{HotkeyType::Key_Tilde, XK_asciitilde},
|
||||
|
||||
{HotkeyType::Key_F1, XK_F1},
|
||||
{HotkeyType::Key_F2, XK_F2},
|
||||
{HotkeyType::Key_F3, XK_F3},
|
||||
@@ -633,6 +674,58 @@ void PressKeys(const std::vector<HotkeyType> keys, int duration)
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
static void initXtst()
|
||||
{
|
||||
libXtstHandle = new QLibrary("libXtst", nullptr);
|
||||
pressFunc = (keyPressFunc)libXtstHandle->resolve("XTestFakeKeyEvent");
|
||||
int _;
|
||||
canSimulateKeyPresses = pressFunc &&
|
||||
XQueryExtension(disp(), "XTEST", &_, &_, &_);
|
||||
}
|
||||
|
||||
static void initXss()
|
||||
{
|
||||
libXssHandle = new QLibrary("libXss", nullptr);
|
||||
allocSSFunc = (XScreenSaverAllocInfoFunc)libXssHandle->resolve(
|
||||
"XScreenSaverAllocInfo");
|
||||
querySSFunc = (XScreenSaverQueryInfoFunc)libXssHandle->resolve(
|
||||
"XScreenSaverQueryInfo");
|
||||
int _;
|
||||
canGetIdleTime = allocSSFunc && querySSFunc &&
|
||||
XQueryExtension(disp(), ScreenSaverName, &_, &_, &_);
|
||||
}
|
||||
|
||||
static void initProcps()
|
||||
{
|
||||
#ifdef PROCPS_AVAILABLE
|
||||
libprocps = new QLibrary("libprocps", nullptr);
|
||||
openproc_ = (openproc_func)libprocps->resolve("openproc");
|
||||
closeproc_ = (closeproc_func)libprocps->resolve("closeproc");
|
||||
readproc_ = (readproc_func)libprocps->resolve("readproc");
|
||||
if (openproc_ && closeproc_ && readproc_) {
|
||||
libprocpsSupported = true;
|
||||
blog(LOG_INFO, "libprocps symbols resolved successfully!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void initProc2()
|
||||
{
|
||||
#ifdef PROCPS2_AVAILABLE
|
||||
libproc2 = new QLibrary("libproc2", nullptr);
|
||||
procps_pids_new_ =
|
||||
(procps_pids_new_func)libproc2->resolve("procps_pids_new");
|
||||
procps_pids_get_ =
|
||||
(procps_pids_get_func)libproc2->resolve("procps_pids_get");
|
||||
procps_pids_unref_ =
|
||||
(procps_pids_unref_func)libproc2->resolve("procps_pids_unref");
|
||||
if (procps_pids_new_ && procps_pids_get_ && procps_pids_unref_) {
|
||||
libprocps2Supported = true;
|
||||
blog(LOG_INFO, "libproc2 symbols resolved successfully!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformInit()
|
||||
{
|
||||
auto display = disp();
|
||||
@@ -640,31 +733,26 @@ void PlatformInit()
|
||||
return;
|
||||
}
|
||||
|
||||
libXtstHandle = new QLibrary("libXtst", nullptr);
|
||||
pressFunc = (keyPressFunc)libXtstHandle->resolve("XTestFakeKeyEvent");
|
||||
int _;
|
||||
canSimulateKeyPresses = pressFunc &&
|
||||
XQueryExtension(disp(), "XTEST", &_, &_, &_);
|
||||
initXtst();
|
||||
initXss();
|
||||
initProcps();
|
||||
initProc2();
|
||||
}
|
||||
|
||||
libXssHandle = new QLibrary("libXss", nullptr);
|
||||
allocSSFunc = (XScreenSaverAllocInfoFunc)libXssHandle->resolve(
|
||||
"XScreenSaverAllocInfo");
|
||||
querySSFunc = (XScreenSaverQueryInfoFunc)libXssHandle->resolve(
|
||||
"XScreenSaverQueryInfo");
|
||||
canGetIdleTime = allocSSFunc && querySSFunc &&
|
||||
XQueryExtension(disp(), ScreenSaverName, &_, &_, &_);
|
||||
static void cleanupHelper(QLibrary *lib)
|
||||
{
|
||||
if (lib) {
|
||||
delete lib;
|
||||
lib = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformCleanup()
|
||||
{
|
||||
if (libXtstHandle) {
|
||||
delete libXtstHandle;
|
||||
libXtstHandle = nullptr;
|
||||
}
|
||||
if (libXssHandle) {
|
||||
delete libXssHandle;
|
||||
libXssHandle = nullptr;
|
||||
}
|
||||
cleanupHelper(libXtstHandle);
|
||||
cleanupHelper(libXssHandle);
|
||||
cleanupHelper(libprocps);
|
||||
cleanupHelper(libproc2);
|
||||
cleanupDisplay();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "macro-action-audio.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -36,6 +36,16 @@ const static std::map<MacroActionAudio::FadeType, std::string> fadeTypes = {
|
||||
"AdvSceneSwitcher.action.audio.fade.type.rate"},
|
||||
};
|
||||
|
||||
namespace {
|
||||
struct FadeInfo {
|
||||
std::atomic_bool active = {false};
|
||||
std::atomic_int id = {0};
|
||||
};
|
||||
}
|
||||
|
||||
static FadeInfo masterAudioFade;
|
||||
static std::unordered_map<std::string, FadeInfo> audioFades;
|
||||
|
||||
constexpr auto fadeInterval = std::chrono::milliseconds(100);
|
||||
constexpr float minFade = 0.000001f;
|
||||
|
||||
@@ -58,10 +68,9 @@ auto set_master_volume = obs_set_master_volume;
|
||||
void MacroActionAudio::SetFadeActive(bool value)
|
||||
{
|
||||
if (_action == Action::SOURCE_VOLUME) {
|
||||
switcher->activeAudioFades[_audioSource.ToString()].active =
|
||||
value;
|
||||
audioFades[_audioSource.ToString()].active = value;
|
||||
} else {
|
||||
switcher->masterAudioFade.active = value;
|
||||
masterAudioFade.active = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,14 +78,13 @@ bool MacroActionAudio::FadeActive()
|
||||
{
|
||||
bool active = true;
|
||||
if (_action == Action::SOURCE_VOLUME) {
|
||||
auto it = switcher->activeAudioFades.find(
|
||||
_audioSource.ToString());
|
||||
if (it == switcher->activeAudioFades.end()) {
|
||||
auto it = audioFades.find(_audioSource.ToString());
|
||||
if (it == audioFades.end()) {
|
||||
return false;
|
||||
}
|
||||
active = it->second.active;
|
||||
} else {
|
||||
active = switcher->masterAudioFade.active;
|
||||
active = masterAudioFade.active;
|
||||
}
|
||||
|
||||
return active;
|
||||
@@ -86,14 +94,13 @@ std::atomic_int *MacroActionAudio::GetFadeIdPtr()
|
||||
{
|
||||
|
||||
if (_action == Action::SOURCE_VOLUME) {
|
||||
auto it = switcher->activeAudioFades.find(
|
||||
_audioSource.ToString());
|
||||
if (it == switcher->activeAudioFades.end()) {
|
||||
auto it = audioFades.find(_audioSource.ToString());
|
||||
if (it == audioFades.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &it->second.id;
|
||||
}
|
||||
return &switcher->masterAudioFade.id;
|
||||
return &masterAudioFade.id;
|
||||
}
|
||||
|
||||
void MacroActionAudio::SetVolume(float vol)
|
||||
|
||||
256
src/macro-core/macro-action-clipboard.cpp
Normal file
256
src/macro-core/macro-action-clipboard.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
#include "macro-action-clipboard.hpp"
|
||||
#include "curl-helper.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QImage>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace advss {
|
||||
|
||||
const std::string MacroActionClipboard::id = "clipboard";
|
||||
|
||||
bool MacroActionClipboard::_registered = MacroActionFactory::Register(
|
||||
MacroActionClipboard::id,
|
||||
{MacroActionClipboard::Create, MacroActionClipboardEdit::Create,
|
||||
"AdvSceneSwitcher.action.clipboard"});
|
||||
|
||||
const static std::map<MacroActionClipboard::Action, std::string> actionTypes = {
|
||||
{MacroActionClipboard::Action::COPY_TEXT,
|
||||
"AdvSceneSwitcher.action.clipboard.type.copy.text"},
|
||||
{MacroActionClipboard::Action::COPY_IMAGE,
|
||||
"AdvSceneSwitcher.action.clipboard.type.copy.image"},
|
||||
};
|
||||
|
||||
static size_t writeCallback(void *ptr, size_t size, size_t nmemb,
|
||||
QByteArray *buffer)
|
||||
{
|
||||
buffer->append((char *)ptr, nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
static std::optional<QImage> getImageFromUrl(const char *url)
|
||||
{
|
||||
QByteArray response;
|
||||
|
||||
CurlHelper::SetOpt(CURLOPT_URL, url);
|
||||
CurlHelper::SetOpt(CURLOPT_HTTPGET, 1L);
|
||||
CurlHelper::SetOpt(CURLOPT_TIMEOUT_MS, 30000);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEFUNCTION, writeCallback);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEDATA, &response);
|
||||
auto code = CurlHelper::Perform();
|
||||
|
||||
if (code != CURLE_OK) {
|
||||
blog(LOG_WARNING,
|
||||
"Retrieving image failed in %s with error: %s", __func__,
|
||||
CurlHelper::GetError(code));
|
||||
return {};
|
||||
}
|
||||
|
||||
return QImage::fromData(response);
|
||||
}
|
||||
|
||||
static void setMimeTypeParams(ClipboardQueueParams *params,
|
||||
QClipboard *clipboard)
|
||||
{
|
||||
auto mimeData = clipboard->mimeData();
|
||||
if (!mimeData) {
|
||||
return;
|
||||
}
|
||||
auto mimeTypeList = mimeData->formats();
|
||||
if (mimeTypeList.empty()) {
|
||||
return;
|
||||
}
|
||||
params->mimeTypePrimary = mimeTypeList.first().toStdString();
|
||||
params->mimeTypeAll = mimeTypeList.join(" ").toStdString();
|
||||
}
|
||||
|
||||
static void copyText(void *param)
|
||||
{
|
||||
auto params = static_cast<ClipboardTextQueueParams *>(param);
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
|
||||
clipboard->setText(params->text.c_str());
|
||||
|
||||
setMimeTypeParams(params, clipboard);
|
||||
}
|
||||
|
||||
static void copyImageFromUrl(void *param)
|
||||
{
|
||||
auto params = static_cast<ClipboardImageQueueParams *>(param);
|
||||
auto url = params->url.c_str();
|
||||
auto image = getImageFromUrl(url);
|
||||
|
||||
if (!image || (*image).isNull()) {
|
||||
blog(LOG_WARNING, "Failed to convert %s URL to image!", url);
|
||||
return;
|
||||
}
|
||||
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setImage(*image);
|
||||
|
||||
setMimeTypeParams(params, clipboard);
|
||||
}
|
||||
|
||||
bool MacroActionClipboard::PerformAction()
|
||||
{
|
||||
switch (_action) {
|
||||
case Action::COPY_TEXT: {
|
||||
ClipboardTextQueueParams params{"", "", _text};
|
||||
obs_queue_task(OBS_TASK_UI, copyText, ¶ms, true);
|
||||
SetTempVarValues(params);
|
||||
break;
|
||||
}
|
||||
case Action::COPY_IMAGE: {
|
||||
ClipboardImageQueueParams params{"", "", _url};
|
||||
obs_queue_task(OBS_TASK_UI, copyImageFromUrl, ¶ms, true);
|
||||
SetTempVarValues(params);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroActionClipboard::SetupTempVars()
|
||||
{
|
||||
MacroAction::SetupTempVars();
|
||||
|
||||
AddTempvar(
|
||||
"mimeType.primary",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.clipboard.mimeType.primary"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.clipboard.mimeType.primary.description"));
|
||||
AddTempvar(
|
||||
"mimeType.all",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.clipboard.mimeType.all"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.clipboard.mimeType.all.description"));
|
||||
}
|
||||
|
||||
void MacroActionClipboard::SetTempVarValues(const ClipboardQueueParams ¶ms)
|
||||
{
|
||||
SetTempVarValue("mimeType.primary", params.mimeTypePrimary);
|
||||
SetTempVarValue("mimeType.all", params.mimeTypeAll);
|
||||
}
|
||||
|
||||
bool MacroActionClipboard::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroAction::Save(obj);
|
||||
obs_data_set_int(obj, "action", static_cast<int>(_action));
|
||||
_text.Save(obj, "text");
|
||||
_url.Save(obj, "url");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroActionClipboard::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Load(obj);
|
||||
_action = static_cast<Action>(obs_data_get_int(obj, "action"));
|
||||
_text.Load(obj, "text");
|
||||
_url.Load(obj, "url");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
{
|
||||
for (const auto &[action, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(action));
|
||||
}
|
||||
}
|
||||
|
||||
MacroActionClipboardEdit::MacroActionClipboardEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionClipboard> entryData)
|
||||
: QWidget(parent),
|
||||
_actions(new FilterComboBox(this)),
|
||||
_text(new VariableLineEdit(this)),
|
||||
_url(new VariableLineEdit(this))
|
||||
{
|
||||
populateActionSelection(_actions);
|
||||
_url->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.action.clipboard.copy.image.url.tooltip"));
|
||||
|
||||
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ActionChanged(int)));
|
||||
QWidget::connect(_text, SIGNAL(editingFinished()), this,
|
||||
SLOT(TextChanged()));
|
||||
QWidget::connect(_url, SIGNAL(editingFinished()), this,
|
||||
SLOT(UrlChanged()));
|
||||
|
||||
auto mainLayout = new QHBoxLayout();
|
||||
mainLayout->addWidget(_actions);
|
||||
mainLayout->addWidget(_text);
|
||||
mainLayout->addWidget(_url);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroActionClipboardEdit::ActionChanged(int index)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_action = static_cast<MacroActionClipboard::Action>(
|
||||
_actions->itemData(index).toInt());
|
||||
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionClipboardEdit::TextChanged()
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_text = _text->text().toStdString();
|
||||
}
|
||||
|
||||
void MacroActionClipboardEdit::UrlChanged()
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_url = _url->text().toStdString();
|
||||
}
|
||||
|
||||
void MacroActionClipboardEdit::SetWidgetVisibility()
|
||||
{
|
||||
_text->setVisible(_entryData->_action ==
|
||||
MacroActionClipboard::Action::COPY_TEXT);
|
||||
_url->setVisible(_entryData->_action ==
|
||||
MacroActionClipboard::Action::COPY_IMAGE);
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroActionClipboardEdit::UpdateEntryData()
|
||||
{
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
_actions->setCurrentIndex(
|
||||
_actions->findData(static_cast<int>(_entryData->_action)));
|
||||
_text->setText(_entryData->_text);
|
||||
_url->setText(_entryData->_url);
|
||||
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
89
src/macro-core/macro-action-clipboard.hpp
Normal file
89
src/macro-core/macro-action-clipboard.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <variable-line-edit.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
struct ClipboardQueueParams {
|
||||
std::string mimeTypePrimary;
|
||||
std::string mimeTypeAll;
|
||||
};
|
||||
|
||||
struct ClipboardTextQueueParams : ClipboardQueueParams {
|
||||
StringVariable text;
|
||||
};
|
||||
|
||||
struct ClipboardImageQueueParams : ClipboardQueueParams {
|
||||
StringVariable url;
|
||||
};
|
||||
|
||||
class MacroActionClipboard : public MacroAction {
|
||||
public:
|
||||
MacroActionClipboard(Macro *m) : MacroAction(m) {}
|
||||
static std::shared_ptr<MacroAction> Create(Macro *m)
|
||||
{
|
||||
return std::make_shared<MacroActionClipboard>(m);
|
||||
}
|
||||
std::string GetId() const { return id; };
|
||||
|
||||
bool PerformAction();
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
|
||||
enum class Action {
|
||||
COPY_TEXT,
|
||||
COPY_IMAGE,
|
||||
};
|
||||
|
||||
Action _action = Action::COPY_TEXT;
|
||||
|
||||
StringVariable _text = obs_module_text(
|
||||
"AdvSceneSwitcher.action.clipboard.copy.text.text.placeholder");
|
||||
StringVariable _url = obs_module_text(
|
||||
"AdvSceneSwitcher.action.clipboard.copy.image.url.placeholder");
|
||||
|
||||
private:
|
||||
void SetupTempVars();
|
||||
void SetTempVarValues(const ClipboardQueueParams ¶ms);
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroActionClipboardEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroActionClipboardEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroActionClipboard> entryData = nullptr);
|
||||
static QWidget *Create(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
return new MacroActionClipboardEdit(
|
||||
parent, std::dynamic_pointer_cast<MacroActionClipboard>(
|
||||
action));
|
||||
}
|
||||
void UpdateEntryData();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MacroActionClipboard> _entryData;
|
||||
|
||||
private slots:
|
||||
void ActionChanged(int index);
|
||||
void TextChanged();
|
||||
void UrlChanged();
|
||||
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
bool _loading = true;
|
||||
|
||||
FilterComboBox *_actions;
|
||||
VariableLineEdit *_text;
|
||||
VariableLineEdit *_url;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "macro-properties.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "macro-action-scene-switch.hpp"
|
||||
#include "section.hpp"
|
||||
#include "switch-button.hpp"
|
||||
@@ -10,61 +12,9 @@
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::map<std::string, MacroActionInfo> &MacroActionFactory::GetMap()
|
||||
{
|
||||
static std::map<std::string, MacroActionInfo> _methods;
|
||||
return _methods;
|
||||
}
|
||||
|
||||
bool MacroActionFactory::Register(const std::string &id, MacroActionInfo info)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it == GetMap().end()) {
|
||||
GetMap()[id] = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<MacroAction> MacroActionFactory::Create(const std::string &id,
|
||||
Macro *m)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end())
|
||||
return it->second._createFunc(m);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidget *MacroActionFactory::CreateWidget(const std::string &id,
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end())
|
||||
return it->second._createWidgetFunc(parent, action);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string MacroActionFactory::GetActionName(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._name;
|
||||
}
|
||||
return "unknown action";
|
||||
}
|
||||
|
||||
std::string MacroActionFactory::GetIdByName(const QString &name)
|
||||
{
|
||||
for (auto it : GetMap()) {
|
||||
if (name == obs_module_text(it.second._name.c_str())) {
|
||||
return it.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
{
|
||||
for (auto &[_, action] : MacroActionFactory::GetActionTypes()) {
|
||||
for (const auto &[_, action] : MacroActionFactory::GetActionTypes()) {
|
||||
QString entry(obs_module_text(action._name.c_str()));
|
||||
if (list->findText(entry) == -1) {
|
||||
list->addItem(entry);
|
||||
@@ -80,7 +30,8 @@ static inline void populateActionSelection(QComboBox *list)
|
||||
MacroActionEdit::MacroActionEdit(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> *entryData,
|
||||
const std::string &id)
|
||||
: MacroSegmentEdit(switcher->macroProperties._highlightActions, parent),
|
||||
: MacroSegmentEdit(GetGlobalMacroProperties()._highlightActions,
|
||||
parent),
|
||||
_actionSelection(new FilterComboBox()),
|
||||
_enable(new SwitchButton()),
|
||||
_entryData(entryData)
|
||||
@@ -134,7 +85,7 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
||||
auto idx = _entryData->get()->GetIndex();
|
||||
auto macro = _entryData->get()->GetMacro();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
_entryData->reset();
|
||||
*_entryData = MacroActionFactory::Create(id, macro);
|
||||
(*_entryData)->SetIndex(idx);
|
||||
@@ -185,7 +136,7 @@ void MacroActionEdit::ActionEnableChanged(bool value)
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
(*_entryData)->SetEnabled(value);
|
||||
SetDisableEffect(!value);
|
||||
}
|
||||
@@ -229,7 +180,7 @@ void AdvSceneSwitcher::AddMacroAction(int idx)
|
||||
id = temp.GetId();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
macro->Actions().emplace(
|
||||
macro->Actions().begin() + idx,
|
||||
MacroActionFactory::Create(id, macro.get()));
|
||||
@@ -280,11 +231,11 @@ void AdvSceneSwitcher::RemoveMacroAction(int idx)
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
ui->actionsList->Remove(idx);
|
||||
macro->Actions().erase(macro->Actions().begin() + idx);
|
||||
switcher->abortMacroWait = true;
|
||||
switcher->macroWaitCv.notify_all();
|
||||
SetMacroAbortWait(true);
|
||||
GetMacroWaitCV().notify_all();
|
||||
macro->UpdateActionIndices();
|
||||
SetActionData(*macro);
|
||||
}
|
||||
@@ -425,7 +376,7 @@ void AdvSceneSwitcher::SwapActions(Macro *m, int pos1, int pos2)
|
||||
std::swap(pos1, pos2);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
iter_swap(m->Actions().begin() + pos1, m->Actions().begin() + pos2);
|
||||
m->UpdateActionIndices();
|
||||
auto widget1 = static_cast<MacroActionEdit *>(
|
||||
@@ -485,7 +436,7 @@ void AdvSceneSwitcher::MacroElseActionReorder(int to, int from)
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto action = macro->ElseActions().at(from);
|
||||
macro->ElseActions().erase(macro->ElseActions().begin() + from);
|
||||
macro->ElseActions().insert(macro->ElseActions().begin() + to,
|
||||
@@ -518,7 +469,7 @@ void AdvSceneSwitcher::AddMacroElseAction(int idx)
|
||||
id = temp.GetId();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
macro->ElseActions().emplace(
|
||||
macro->ElseActions().begin() + idx,
|
||||
MacroActionFactory::Create(id, macro.get()));
|
||||
@@ -550,11 +501,11 @@ void AdvSceneSwitcher::RemoveMacroElseAction(int idx)
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
ui->elseActionsList->Remove(idx);
|
||||
macro->ElseActions().erase(macro->ElseActions().begin() + idx);
|
||||
switcher->abortMacroWait = true;
|
||||
switcher->macroWaitCv.notify_all();
|
||||
SetMacroAbortWait(true);
|
||||
GetMacroWaitCV().notify_all();
|
||||
macro->UpdateElseActionIndices();
|
||||
SetActionData(*macro);
|
||||
}
|
||||
@@ -572,7 +523,7 @@ void AdvSceneSwitcher::SwapElseActions(Macro *m, int pos1, int pos2)
|
||||
std::swap(pos1, pos2);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
iter_swap(m->ElseActions().begin() + pos1,
|
||||
m->ElseActions().begin() + pos2);
|
||||
m->UpdateElseActionIndices();
|
||||
@@ -635,7 +586,7 @@ void AdvSceneSwitcher::MacroActionReorder(int to, int from)
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto action = macro->Actions().at(from);
|
||||
macro->Actions().erase(macro->Actions().begin() + from);
|
||||
macro->Actions().insert(macro->Actions().begin() + to, action);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "macro-action.hpp"
|
||||
#include "macro-action-factory.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <memory>
|
||||
@@ -8,32 +9,6 @@ namespace advss {
|
||||
|
||||
class SwitchButton;
|
||||
|
||||
struct MacroActionInfo {
|
||||
using TCreateMethod = std::shared_ptr<MacroAction> (*)(Macro *m);
|
||||
using TCreateWidgetMethod = QWidget *(*)(QWidget *parent,
|
||||
std::shared_ptr<MacroAction>);
|
||||
TCreateMethod _createFunc = nullptr;
|
||||
TCreateWidgetMethod _createWidgetFunc = nullptr;
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
class MacroActionFactory {
|
||||
public:
|
||||
MacroActionFactory() = delete;
|
||||
|
||||
static bool Register(const std::string &id, MacroActionInfo);
|
||||
static std::shared_ptr<MacroAction> Create(const std::string &id,
|
||||
Macro *m);
|
||||
static QWidget *CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action);
|
||||
static auto GetActionTypes() { return GetMap(); }
|
||||
static std::string GetActionName(const std::string &id);
|
||||
static std::string GetIdByName(const QString &name);
|
||||
|
||||
private:
|
||||
static std::map<std::string, MacroActionInfo> &GetMap();
|
||||
};
|
||||
|
||||
class MacroActionEdit : public MacroSegmentEdit {
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
57
src/macro-core/macro-action-factory.cpp
Normal file
57
src/macro-core/macro-action-factory.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "macro-action-factory.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::map<std::string, MacroActionInfo> &MacroActionFactory::GetMap()
|
||||
{
|
||||
static std::map<std::string, MacroActionInfo> _methods;
|
||||
return _methods;
|
||||
}
|
||||
|
||||
bool MacroActionFactory::Register(const std::string &id, MacroActionInfo info)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it == GetMap().end()) {
|
||||
GetMap()[id] = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<MacroAction> MacroActionFactory::Create(const std::string &id,
|
||||
Macro *m)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end())
|
||||
return it->second._create(m);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidget *MacroActionFactory::CreateWidget(const std::string &id,
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end())
|
||||
return it->second._createWidget(parent, action);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string MacroActionFactory::GetActionName(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._name;
|
||||
}
|
||||
return "unknown action";
|
||||
}
|
||||
|
||||
std::string MacroActionFactory::GetIdByName(const QString &name)
|
||||
{
|
||||
for (auto it : GetMap()) {
|
||||
if (name == obs_module_text(it.second._name.c_str())) {
|
||||
return it.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
34
src/macro-core/macro-action-factory.hpp
Normal file
34
src/macro-core/macro-action-factory.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "macro-action.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace advss {
|
||||
|
||||
struct MacroActionInfo {
|
||||
using CreateAction = std::shared_ptr<MacroAction> (*)(Macro *m);
|
||||
using CreateActionWidget = QWidget *(*)(QWidget *parent,
|
||||
std::shared_ptr<MacroAction>);
|
||||
CreateAction _create = nullptr;
|
||||
CreateActionWidget _createWidget = nullptr;
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
class MacroActionFactory {
|
||||
public:
|
||||
MacroActionFactory() = delete;
|
||||
|
||||
static bool Register(const std::string &id, MacroActionInfo);
|
||||
static std::shared_ptr<MacroAction> Create(const std::string &id,
|
||||
Macro *m);
|
||||
static QWidget *CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action);
|
||||
static auto GetActionTypes() { return GetMap(); }
|
||||
static std::string GetActionName(const std::string &id);
|
||||
static std::string GetIdByName(const QString &name);
|
||||
|
||||
private:
|
||||
static std::map<std::string, MacroActionInfo> &GetMap();
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
@@ -424,11 +424,16 @@ void MacroActionFilterEdit::SetWidgetVisibility()
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionFilter::SettingsInputMethod::
|
||||
INDIVIDUAL_TEMPVAR);
|
||||
_manualSettingValue->setVisible(
|
||||
_entryData->_action == MacroActionFilter::Action::SETTINGS &&
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionFilter::SettingsInputMethod::
|
||||
INDIVIDUAL_MANUAL);
|
||||
|
||||
if (_entryData->_action == MacroActionFilter::Action::SETTINGS &&
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionFilter::SettingsInputMethod::INDIVIDUAL_MANUAL) {
|
||||
RemoveStretchIfPresent(_settingsLayout);
|
||||
_manualSettingValue->show();
|
||||
} else {
|
||||
AddStretchIfNecessary(_settingsLayout);
|
||||
_manualSettingValue->hide();
|
||||
}
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
|
||||
@@ -14,14 +14,14 @@ bool MacroActionHotkey::_registered = MacroActionFactory::Register(
|
||||
{MacroActionHotkey::Create, MacroActionHotkeyEdit::Create,
|
||||
"AdvSceneSwitcher.action.hotkey"});
|
||||
|
||||
const static std::map<MacroActionHotkey::Action, std::string> actionTypes = {
|
||||
static const std::map<MacroActionHotkey::Action, std::string> actionTypes = {
|
||||
{MacroActionHotkey::Action::OBS_HOTKEY,
|
||||
"AdvSceneSwitcher.action.hotkey.type.obs"},
|
||||
{MacroActionHotkey::Action::CUSTOM,
|
||||
"AdvSceneSwitcher.action.hotkey.type.custom"},
|
||||
};
|
||||
|
||||
const static std::map<obs_hotkey_registerer_type, std::string> hotkeyTypes = {
|
||||
static const std::map<obs_hotkey_registerer_type, std::string> hotkeyTypes = {
|
||||
{OBS_HOTKEY_REGISTERER_FRONTEND,
|
||||
"AdvSceneSwitcher.action.hotkey.type.obs.type.frontend"},
|
||||
{OBS_HOTKEY_REGISTERER_SOURCE,
|
||||
@@ -34,7 +34,7 @@ const static std::map<obs_hotkey_registerer_type, std::string> hotkeyTypes = {
|
||||
"AdvSceneSwitcher.action.hotkey.type.obs.type.service"},
|
||||
};
|
||||
|
||||
static std::unordered_map<HotkeyType, long> keyTable = {
|
||||
static const std::unordered_map<HotkeyType, long> keyTable = {
|
||||
// Chars
|
||||
{HotkeyType::Key_A, OBS_KEY_A},
|
||||
{HotkeyType::Key_B, OBS_KEY_B},
|
||||
@@ -75,6 +75,9 @@ static std::unordered_map<HotkeyType, long> keyTable = {
|
||||
{HotkeyType::Key_8, OBS_KEY_8},
|
||||
{HotkeyType::Key_9, OBS_KEY_9},
|
||||
|
||||
// Other
|
||||
{HotkeyType::Key_Tilde, OBS_KEY_ASCIITILDE},
|
||||
|
||||
{HotkeyType::Key_F1, OBS_KEY_F1},
|
||||
{HotkeyType::Key_F2, OBS_KEY_F2},
|
||||
{HotkeyType::Key_F3, OBS_KEY_F3},
|
||||
@@ -525,6 +528,7 @@ static inline void populateKeySelection(QComboBox *list)
|
||||
list->addItem("NumpadDivide");
|
||||
list->addItem("NumpadDecimal");
|
||||
list->addItem("NumpadEnter");
|
||||
list->addItem("Tilde");
|
||||
}
|
||||
|
||||
static void populateActionSelection(QComboBox *list)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-action-http.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "curl-helper.hpp"
|
||||
|
||||
@@ -36,44 +35,44 @@ void MacroActionHttp::SetupHeaders()
|
||||
}
|
||||
struct curl_slist *headers = nullptr;
|
||||
for (auto &header : _headers) {
|
||||
headers = switcher->curl.SlistAppend(headers, header.c_str());
|
||||
headers = CurlHelper::SlistAppend(headers, header.c_str());
|
||||
}
|
||||
if (!_headers.empty()) {
|
||||
switcher->curl.SetOpt(CURLOPT_HTTPHEADER, headers);
|
||||
CurlHelper::SetOpt(CURLOPT_HTTPHEADER, headers);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionHttp::Get()
|
||||
{
|
||||
switcher->curl.SetOpt(CURLOPT_URL, _url.c_str());
|
||||
switcher->curl.SetOpt(CURLOPT_HTTPGET, 1L);
|
||||
switcher->curl.SetOpt(CURLOPT_TIMEOUT_MS, _timeout.Milliseconds());
|
||||
CurlHelper::SetOpt(CURLOPT_URL, _url.c_str());
|
||||
CurlHelper::SetOpt(CURLOPT_HTTPGET, 1L);
|
||||
CurlHelper::SetOpt(CURLOPT_TIMEOUT_MS, _timeout.Milliseconds());
|
||||
SetupHeaders();
|
||||
|
||||
std::string response;
|
||||
if (IsReferencedInVars()) {
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEFUNCTION, WriteCB);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEFUNCTION, WriteCB);
|
||||
} else {
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEFUNCTION, DropCB);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEFUNCTION, DropCB);
|
||||
}
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEDATA, &response);
|
||||
switcher->curl.Perform();
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEDATA, &response);
|
||||
CurlHelper::Perform();
|
||||
|
||||
SetVariableValue(response);
|
||||
}
|
||||
|
||||
void MacroActionHttp::Post()
|
||||
{
|
||||
switcher->curl.SetOpt(CURLOPT_URL, _url.c_str());
|
||||
switcher->curl.SetOpt(CURLOPT_POSTFIELDS, _data.c_str());
|
||||
switcher->curl.SetOpt(CURLOPT_TIMEOUT_MS, _timeout.Milliseconds());
|
||||
CurlHelper::SetOpt(CURLOPT_URL, _url.c_str());
|
||||
CurlHelper::SetOpt(CURLOPT_POSTFIELDS, _data.c_str());
|
||||
CurlHelper::SetOpt(CURLOPT_TIMEOUT_MS, _timeout.Milliseconds());
|
||||
SetupHeaders();
|
||||
switcher->curl.Perform();
|
||||
CurlHelper::Perform();
|
||||
}
|
||||
|
||||
bool MacroActionHttp::PerformAction()
|
||||
{
|
||||
if (!switcher->curl.Initialized()) {
|
||||
if (!CurlHelper::Initialized()) {
|
||||
blog(LOG_WARNING,
|
||||
"cannot perform http action (curl not found)");
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "macro-action-plugin-state.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <QMainWindow>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
@@ -27,40 +28,38 @@ const static std::map<PluginStateAction, std::string> actionTypes = {
|
||||
"AdvSceneSwitcher.action.pluginState.type.terminate"},
|
||||
};
|
||||
|
||||
const static std::map<SwitcherData::NoMatch, std::string> noMatchValues = {
|
||||
{SwitcherData::NoMatch::NO_SWITCH,
|
||||
const static std::map<NoMatchBehavior, std::string> noMatchValues = {
|
||||
{NoMatchBehavior::NO_SWITCH,
|
||||
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.dontSwitch"},
|
||||
{SwitcherData::NoMatch::SWITCH,
|
||||
{NoMatchBehavior::SWITCH,
|
||||
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo"},
|
||||
{SwitcherData::NoMatch::RANDOM_SWITCH,
|
||||
{NoMatchBehavior::RANDOM_SWITCH,
|
||||
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchToRandom"},
|
||||
};
|
||||
|
||||
static void stopPlugin()
|
||||
{
|
||||
std::thread t([]() { switcher->Stop(); });
|
||||
std::thread t([]() { StopPlugin(); });
|
||||
t.detach();
|
||||
}
|
||||
|
||||
static void importSettings(const std::string &path)
|
||||
{
|
||||
if (switcher->settingsWindowOpened) {
|
||||
if (SettingsWindowIsOpened()) {
|
||||
return;
|
||||
}
|
||||
obs_data_t *obj = obs_data_create_from_json_file(path.c_str());
|
||||
OBSDataAutoRelease obj = obs_data_create_from_json_file(path.c_str());
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
switcher->LoadSettings(obj);
|
||||
obs_data_release(obj);
|
||||
LoadPluginSettings(obj);
|
||||
}
|
||||
|
||||
static void setNoMatchBehaviour(int value, OBSWeakSource &scene)
|
||||
{
|
||||
switcher->switchIfNotMatching =
|
||||
static_cast<SwitcherData::NoMatch>(value);
|
||||
if (switcher->switchIfNotMatching == SwitcherData::NoMatch::SWITCH) {
|
||||
switcher->nonMatchingScene = scene;
|
||||
SetPluginNoMatchBehavior(static_cast<NoMatchBehavior>(value));
|
||||
if (GetPluginNoMatchBehavior() == NoMatchBehavior::SWITCH) {
|
||||
SetNoMatchScene(scene);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,8 +341,8 @@ void MacroActionPluginStateEdit::SetWidgetVisibility()
|
||||
break;
|
||||
case PluginStateAction::NO_MATCH_BEHAVIOUR:
|
||||
_values->show();
|
||||
if (static_cast<SwitcherData::NoMatch>(_entryData->_value) ==
|
||||
SwitcherData::NoMatch::SWITCH) {
|
||||
if (static_cast<NoMatchBehavior>(_entryData->_value) ==
|
||||
NoMatchBehavior::SWITCH) {
|
||||
_scenes->show();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -14,9 +14,14 @@ bool MacroActionRun::_registered = MacroActionFactory::Register(
|
||||
|
||||
bool MacroActionRun::PerformAction()
|
||||
{
|
||||
bool procStarted = QProcess::startDetached(
|
||||
QString::fromStdString(_procConfig.Path()), _procConfig.Args(),
|
||||
QString::fromStdString(_procConfig.WorkingDir()));
|
||||
if (_wait) {
|
||||
_procConfig.StartProcessAndWait(_timeout.Milliseconds());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool procStarted = _procConfig.StartProcessDetached();
|
||||
|
||||
// Fall back to using default application to open given file
|
||||
if (!procStarted && _procConfig.Args().empty()) {
|
||||
vblog(LOG_INFO, "run \"%s\" using QDesktopServices",
|
||||
_procConfig.Path().c_str());
|
||||
@@ -35,6 +40,9 @@ bool MacroActionRun::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroAction::Save(obj);
|
||||
_procConfig.Save(obj);
|
||||
_timeout.Save(obj);
|
||||
obs_data_set_bool(obj, "wait", _wait);
|
||||
obs_data_set_int(obj, "version", 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,6 +50,12 @@ bool MacroActionRun::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Load(obj);
|
||||
_procConfig.Load(obj);
|
||||
// TODO: Remove this fallback in a future version
|
||||
if (!obs_data_has_user_value(obj, "version")) {
|
||||
return true;
|
||||
}
|
||||
_timeout.Load(obj);
|
||||
_wait = obs_data_get_bool(obj, "wait");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,14 +66,30 @@ std::string MacroActionRun::GetShortDesc() const
|
||||
|
||||
MacroActionRunEdit::MacroActionRunEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionRun> entryData)
|
||||
: QWidget(parent), _procConfig(new ProcessConfigEdit(this))
|
||||
: QWidget(parent),
|
||||
_procConfig(new ProcessConfigEdit(this)),
|
||||
_waitLayout(new QHBoxLayout()),
|
||||
_wait(new QCheckBox()),
|
||||
_timeout(new DurationSelection(this, true, 0.1))
|
||||
{
|
||||
QWidget::connect(_procConfig,
|
||||
SIGNAL(ConfigChanged(const ProcessConfig &)), this,
|
||||
SLOT(ProcessConfigChanged(const ProcessConfig &)));
|
||||
QWidget::connect(_procConfig, SIGNAL(AdvancedSettingsEnabled()), this,
|
||||
SLOT(ProcessConfigAdvancedSettingsShown()));
|
||||
QWidget::connect(_wait, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(WaitChanged(int)));
|
||||
QWidget::connect(_timeout, SIGNAL(DurationChanged(const Duration &)),
|
||||
this, SLOT(TimeoutChanged(const Duration &)));
|
||||
|
||||
auto *layout = new QVBoxLayout;
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.run.entry.wait"),
|
||||
_waitLayout,
|
||||
{{"{{wait}}", _wait}, {"{{timeout}}", _timeout}});
|
||||
SetLayoutVisible(_waitLayout, false);
|
||||
|
||||
auto layout = new QVBoxLayout;
|
||||
layout->addWidget(_procConfig);
|
||||
layout->addLayout(_waitLayout);
|
||||
setLayout(layout);
|
||||
|
||||
_entryData = entryData;
|
||||
@@ -73,6 +103,31 @@ void MacroActionRunEdit::UpdateEntryData()
|
||||
return;
|
||||
}
|
||||
_procConfig->SetProcessConfig(_entryData->_procConfig);
|
||||
_wait->setChecked(_entryData->_wait);
|
||||
_timeout->SetDuration(_entryData->_timeout);
|
||||
}
|
||||
|
||||
void MacroActionRunEdit::ProcessConfigAdvancedSettingsShown()
|
||||
{
|
||||
SetLayoutVisible(_waitLayout, true);
|
||||
}
|
||||
|
||||
void MacroActionRunEdit::WaitChanged(int value)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
auto lock = LockContext();
|
||||
_entryData->_wait = value;
|
||||
}
|
||||
|
||||
void MacroActionRunEdit::TimeoutChanged(const Duration &timeout)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
auto lock = LockContext();
|
||||
_entryData->_timeout = timeout;
|
||||
}
|
||||
|
||||
void MacroActionRunEdit::ProcessConfigChanged(const ProcessConfig &conf)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "process-config.hpp"
|
||||
#include "duration-control.hpp"
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -19,6 +22,8 @@ public:
|
||||
}
|
||||
|
||||
ProcessConfig _procConfig;
|
||||
bool _wait = false;
|
||||
Duration _timeout = 1;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
@@ -42,14 +47,19 @@ public:
|
||||
|
||||
private slots:
|
||||
void ProcessConfigChanged(const ProcessConfig &);
|
||||
void ProcessConfigAdvancedSettingsShown();
|
||||
void WaitChanged(int);
|
||||
void TimeoutChanged(const Duration &);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MacroActionRun> _entryData;
|
||||
|
||||
private:
|
||||
ProcessConfigEdit *_procConfig;
|
||||
QHBoxLayout *_waitLayout;
|
||||
QCheckBox *_wait;
|
||||
DurationSelection *_timeout;
|
||||
|
||||
std::shared_ptr<MacroActionRun> _entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "macro-action-scene-collection.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -17,7 +17,7 @@ bool MacroActionSceneCollection::PerformAction()
|
||||
// Changing the scene collection will also reload the settings of the
|
||||
// scene switcher, so to avoid issues of not being able to change
|
||||
// settings ignore this action if the settings dialog is opened.
|
||||
if (switcher->settingsWindowOpened) {
|
||||
if (SettingsWindowIsOpened()) {
|
||||
return false;
|
||||
}
|
||||
obs_frontend_set_current_scene_collection(_sceneCollection.c_str());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "macro-action-scene-switch.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "scene-switch-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -7,7 +9,7 @@ namespace advss {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
const std::string MacroActionSwitchScene::id = "scene_switch";
|
||||
const std::string MacroActionSwitchScene::id = GetSceneSwitchActionId().data();
|
||||
|
||||
bool MacroActionSwitchScene::_registered = MacroActionFactory::Register(
|
||||
MacroActionSwitchScene::id,
|
||||
@@ -33,9 +35,9 @@ static void waitForTransitionChange(OBSWeakSource &transition,
|
||||
}
|
||||
|
||||
bool stillTransitioning = true;
|
||||
while (stillTransitioning && !switcher->abortMacroWait &&
|
||||
while (stillTransitioning && !MacroWaitShouldAbort() &&
|
||||
!macro->GetStop()) {
|
||||
switcher->macroTransitionCv.wait_for(*lock, time);
|
||||
GetMacroTransitionCV().wait_for(*lock, time);
|
||||
float t = obs_transition_get_time(source);
|
||||
stillTransitioning = t < 1.0f && t > 0.0f;
|
||||
}
|
||||
@@ -49,8 +51,8 @@ static void waitForTransitionChangeFixedDuration(
|
||||
auto time = std::chrono::high_resolution_clock::now() +
|
||||
std::chrono::milliseconds(duration);
|
||||
|
||||
while (!switcher->abortMacroWait && !macro->GetStop()) {
|
||||
if (switcher->macroTransitionCv.wait_until(*lock, time) ==
|
||||
while (!MacroWaitShouldAbort() && !macro->GetStop()) {
|
||||
if (GetMacroTransitionCV().wait_until(*lock, time) ==
|
||||
std::cv_status::timeout) {
|
||||
break;
|
||||
}
|
||||
@@ -91,11 +93,16 @@ static OBSWeakSource getOverrideTransition(OBSWeakSource &scene)
|
||||
return transition;
|
||||
}
|
||||
|
||||
static int getExpectedTransitionDuration(OBSWeakSource &scene, OBSWeakSource &t,
|
||||
static int getExpectedTransitionDuration(OBSWeakSource &scene,
|
||||
OBSWeakSource &transiton_,
|
||||
double duration)
|
||||
{
|
||||
OBSWeakSource transition = t;
|
||||
if (!switcher->transitionOverrideOverride) {
|
||||
OBSWeakSource transition = transiton_;
|
||||
|
||||
// If we are not modifying the transition override, we will have to
|
||||
// check, if a transition override is set by the user and use its
|
||||
// duration instead
|
||||
if (!ShouldModifyTransitionOverrides()) {
|
||||
auto overrideTransition = getOverrideTransition(scene);
|
||||
if (overrideTransition) {
|
||||
transition = overrideTransition;
|
||||
@@ -104,6 +111,7 @@ static int getExpectedTransitionDuration(OBSWeakSource &scene, OBSWeakSource &t,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isUsingFixedLengthTransition(transition)) {
|
||||
return -1; // no API is available to access the fixed duration
|
||||
}
|
||||
@@ -118,9 +126,9 @@ bool MacroActionSwitchScene::WaitForTransition(OBSWeakSource &scene,
|
||||
{
|
||||
const int expectedTransitionDuration = getExpectedTransitionDuration(
|
||||
scene, transition, _duration.Seconds());
|
||||
switcher->abortMacroWait = false;
|
||||
SetMacroAbortWait(false);
|
||||
|
||||
std::unique_lock<std::mutex> lock(switcher->m);
|
||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||
if (expectedTransitionDuration < 0) {
|
||||
waitForTransitionChange(transition, &lock, GetMacro());
|
||||
} else {
|
||||
@@ -128,7 +136,7 @@ bool MacroActionSwitchScene::WaitForTransition(OBSWeakSource &scene,
|
||||
&lock, GetMacro());
|
||||
}
|
||||
|
||||
return !switcher->abortMacroWait;
|
||||
return !MacroWaitShouldAbort();
|
||||
}
|
||||
|
||||
bool MacroActionSwitchScene::PerformAction()
|
||||
@@ -145,7 +153,7 @@ bool MacroActionSwitchScene::PerformAction()
|
||||
auto transition = _transition.GetTransition();
|
||||
SwitchScene({scene, transition, (int)(_duration.Milliseconds())},
|
||||
obs_frontend_preview_program_mode_active());
|
||||
if (_blockUntilTransitionDone && scene) {
|
||||
if (_blockUntilTransitionDone && scene && scene != GetCurrentScene()) {
|
||||
return WaitForTransition(scene, transition);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -32,7 +32,7 @@ void MacroActionScreenshot::CustomScreenshot(OBSWeakSource &source)
|
||||
}
|
||||
auto s = obs_weak_source_get_source(source);
|
||||
_screenshot.~ScreenshotHelper();
|
||||
new (&_screenshot) ScreenshotHelper(s, false, 0, true, _path);
|
||||
new (&_screenshot) ScreenshotHelper(s, QRect(), false, 0, true, _path);
|
||||
obs_source_release(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -601,11 +601,17 @@ void MacroActionSourceEdit::SetWidgetVisibility()
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionSource::SettingsInputMethod::
|
||||
INDIVIDUAL_TEMPVAR);
|
||||
_manualSettingValue->setVisible(
|
||||
_entryData->_action == MacroActionSource::Action::SETTINGS &&
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionSource::SettingsInputMethod::
|
||||
INDIVIDUAL_MANUAL);
|
||||
|
||||
if (_entryData->_action == MacroActionSource::Action::SETTINGS &&
|
||||
_entryData->_settingsInputMethod ==
|
||||
MacroActionSource::SettingsInputMethod::INDIVIDUAL_MANUAL) {
|
||||
RemoveStretchIfPresent(_settingsLayout);
|
||||
_manualSettingValue->show();
|
||||
} else {
|
||||
AddStretchIfNecessary(_settingsLayout);
|
||||
_manualSettingValue->hide();
|
||||
}
|
||||
|
||||
const bool showWarning =
|
||||
_entryData->_action == MacroActionSource::Action::ENABLE ||
|
||||
_entryData->_action == MacroActionSource::Action::DISABLE;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "macro-action-variable.hpp"
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "math-helpers.hpp"
|
||||
@@ -51,6 +50,8 @@ const static std::map<MacroActionVariable::Type, std::string> actionTypes = {
|
||||
"AdvSceneSwitcher.action.variable.type.extractJson"},
|
||||
{MacroActionVariable::Type::SET_TO_TEMPVAR,
|
||||
"AdvSceneSwitcher.action.variable.type.setToTempvar"},
|
||||
{MacroActionVariable::Type::SCENE_ITEM_NAME,
|
||||
"AdvSceneSwitcher.action.variable.type.sceneItemName"},
|
||||
};
|
||||
|
||||
static void apppend(Variable &var, const std::string &value)
|
||||
@@ -134,6 +135,49 @@ void MacroActionVariable::HandleMathExpression(Variable *var)
|
||||
var->SetValue(std::get<double>(result));
|
||||
}
|
||||
|
||||
struct GetSceneItemNameHelper {
|
||||
int curIdx = 0;
|
||||
int targetIdx = 0;
|
||||
std::string name = "";
|
||||
};
|
||||
|
||||
static bool getSceneItemAtIdx(obs_scene_t *, obs_sceneitem_t *item, void *ptr)
|
||||
{
|
||||
auto data = reinterpret_cast<GetSceneItemNameHelper *>(ptr);
|
||||
if (obs_sceneitem_is_group(item)) {
|
||||
obs_scene_t *scene = obs_sceneitem_group_get_scene(item);
|
||||
obs_scene_enum_items(scene, getSceneItemAtIdx, ptr);
|
||||
}
|
||||
if (data->curIdx == data->targetIdx) {
|
||||
data->name =
|
||||
obs_source_get_name(obs_sceneitem_get_source(item));
|
||||
data->curIdx--;
|
||||
return false;
|
||||
}
|
||||
data->curIdx--;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroActionVariable::SetToSceneItemName(Variable *var)
|
||||
{
|
||||
auto weakSource = _scene.GetScene();
|
||||
if (!weakSource) {
|
||||
var->SetValue("");
|
||||
return;
|
||||
}
|
||||
auto index = _sceneItemIndex.GetValue();
|
||||
if (index < 1) {
|
||||
var->SetValue("");
|
||||
return;
|
||||
}
|
||||
auto sceneItemCount = GetSceneItemCount(weakSource);
|
||||
OBSSourceAutoRelease source = obs_weak_source_get_source(weakSource);
|
||||
auto scene = obs_scene_from_source(source);
|
||||
GetSceneItemNameHelper data{sceneItemCount, index};
|
||||
obs_scene_enum_items(scene, getSceneItemAtIdx, &data);
|
||||
var->SetValue(data.name);
|
||||
}
|
||||
|
||||
struct AskForInputParams {
|
||||
QString prompt;
|
||||
QString placeholder;
|
||||
@@ -268,6 +312,9 @@ bool MacroActionVariable::PerformAction()
|
||||
var->SetValue(*value);
|
||||
return true;
|
||||
}
|
||||
case Type::SCENE_ITEM_NAME:
|
||||
SetToSceneItemName(var.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -299,6 +346,7 @@ bool MacroActionVariable::Save(obs_data_t *obj) const
|
||||
_envVariableName.Save(obj, "environmentVariableName");
|
||||
_scene.Save(obj);
|
||||
_tempVar.Save(obj);
|
||||
_sceneItemIndex.Save(obj, "sceneItemIndex");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -328,6 +376,7 @@ bool MacroActionVariable::Load(obs_data_t *obj)
|
||||
_envVariableName.Load(obj, "environmentVariableName");
|
||||
_scene.Load(obj);
|
||||
_tempVar.Load(obj, GetMacro());
|
||||
_sceneItemIndex.Load(obj, "sceneItemIndex");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -457,7 +506,8 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
||||
_envVariable(new VariableLineEdit(this)),
|
||||
_scenes(new SceneSelectionWidget(this, true, false, true, true,
|
||||
true)),
|
||||
_tempVars(new TempVariableSelection(this))
|
||||
_tempVars(new TempVariableSelection(this)),
|
||||
_sceneItemIndex(new VariableSpinBox())
|
||||
{
|
||||
_numValue->setMinimum(-9999999999);
|
||||
_numValue->setMaximum(9999999999);
|
||||
@@ -475,6 +525,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
||||
_regexMatchIdx->setSuffix(".");
|
||||
_inputPrompt->setSizePolicy(QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::Preferred);
|
||||
_sceneItemIndex->setMinimum(1);
|
||||
populateTypeSelection(_actions);
|
||||
|
||||
QWidget::connect(_variables, SIGNAL(SelectionChanged(const QString &)),
|
||||
@@ -523,6 +574,10 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
||||
QWidget::connect(_tempVars,
|
||||
SIGNAL(SelectionChanged(const TempVariableRef &)),
|
||||
this, SLOT(SelectionChanged(const TempVariableRef &)));
|
||||
QWidget::connect(
|
||||
_sceneItemIndex,
|
||||
SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
|
||||
this, SLOT(SceneItemIndexChanged(const NumberVariable<int> &)));
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{variables}}", _variables},
|
||||
@@ -544,6 +599,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
||||
{"{{envVariableName}}", _envVariable},
|
||||
{"{{scenes}}", _scenes},
|
||||
{"{{tempVars}}", _tempVars},
|
||||
{"{{sceneItemIndex}}", _sceneItemIndex},
|
||||
};
|
||||
auto entryLayout = new QHBoxLayout;
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.variable.entry"),
|
||||
@@ -638,6 +694,7 @@ void MacroActionVariableEdit::UpdateEntryData()
|
||||
_envVariable->setText(_entryData->_envVariableName);
|
||||
_scenes->SetScene(_entryData->_scene);
|
||||
_tempVars->SetVariable(_entryData->_tempVar);
|
||||
_sceneItemIndex->SetValue(_entryData->_sceneItemIndex);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
@@ -982,6 +1039,17 @@ void MacroActionVariableEdit::SelectionChanged(const TempVariableRef &var)
|
||||
_entryData->_tempVar = var;
|
||||
}
|
||||
|
||||
void MacroActionVariableEdit::SceneItemIndexChanged(
|
||||
const NumberVariable<int> &value)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_sceneItemIndex = value;
|
||||
}
|
||||
|
||||
void MacroActionVariableEdit::SetWidgetVisibility()
|
||||
{
|
||||
if (!_entryData) {
|
||||
@@ -1058,10 +1126,15 @@ void MacroActionVariableEdit::SetWidgetVisibility()
|
||||
}
|
||||
_envVariable->setVisible(_entryData->_type ==
|
||||
MacroActionVariable::Type::ENV_VARIABLE);
|
||||
_scenes->setVisible(_entryData->_type ==
|
||||
MacroActionVariable::Type::SCENE_ITEM_COUNT);
|
||||
_scenes->setVisible(
|
||||
_entryData->_type ==
|
||||
MacroActionVariable::Type::SCENE_ITEM_COUNT ||
|
||||
_entryData->_type ==
|
||||
MacroActionVariable::Type::SCENE_ITEM_NAME);
|
||||
_tempVars->setVisible(_entryData->_type ==
|
||||
MacroActionVariable::Type::SET_TO_TEMPVAR);
|
||||
_sceneItemIndex->setVisible(_entryData->_type ==
|
||||
MacroActionVariable::Type::SCENE_ITEM_NAME);
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "scene-selection.hpp"
|
||||
#include "variable-line-edit.hpp"
|
||||
#include "variable-text-edit.hpp"
|
||||
#include "variable-spinbox.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -44,6 +45,7 @@ public:
|
||||
STRING_LENGTH,
|
||||
EXTRACT_JSON,
|
||||
SET_TO_TEMPVAR,
|
||||
SCENE_ITEM_NAME,
|
||||
};
|
||||
|
||||
Type _type = Type::SET_FIXED_VALUE;
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
#endif
|
||||
SceneSelection _scene;
|
||||
TempVariableRef _tempVar;
|
||||
IntVariable _sceneItemIndex = 1;
|
||||
|
||||
private:
|
||||
void DecrementCurrentSegmentVariableRef();
|
||||
@@ -82,6 +85,7 @@ private:
|
||||
void HandleRegexSubString(Variable *);
|
||||
void HandleFindAndReplace(Variable *);
|
||||
void HandleMathExpression(Variable *);
|
||||
void SetToSceneItemName(Variable *);
|
||||
|
||||
std::weak_ptr<MacroSegment> _macroSegment;
|
||||
int _segmentIdxLoadValue = -1;
|
||||
@@ -129,6 +133,7 @@ private slots:
|
||||
void EnvVariableChanged();
|
||||
void SceneChanged(const SceneSelection &);
|
||||
void SelectionChanged(const TempVariableRef &var);
|
||||
void SceneItemIndexChanged(const NumberVariable<int> &);
|
||||
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
@@ -167,6 +172,7 @@ private:
|
||||
VariableLineEdit *_envVariable;
|
||||
SceneSelectionWidget *_scenes;
|
||||
TempVariableSelection *_tempVars;
|
||||
VariableSpinBox *_sceneItemIndex;
|
||||
|
||||
std::shared_ptr<MacroActionVariable> _entryData;
|
||||
QTimer _timer;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "macro-action-wait.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <random>
|
||||
@@ -24,8 +26,8 @@ static std::default_random_engine re(rd());
|
||||
static void waitHelper(std::unique_lock<std::mutex> *lock, Macro *macro,
|
||||
std::chrono::high_resolution_clock::time_point &time)
|
||||
{
|
||||
while (!switcher->abortMacroWait && !macro->GetStop()) {
|
||||
if (switcher->macroWaitCv.wait_until(*lock, time) ==
|
||||
while (!MacroWaitShouldAbort() && !macro->GetStop()) {
|
||||
if (GetMacroWaitCV().wait_until(*lock, time) ==
|
||||
std::cv_status::timeout) {
|
||||
break;
|
||||
}
|
||||
@@ -53,11 +55,11 @@ bool MacroActionWait::PerformAction()
|
||||
auto time = std::chrono::high_resolution_clock::now() +
|
||||
std::chrono::milliseconds((int)(sleepDuration * 1000));
|
||||
|
||||
switcher->abortMacroWait = false;
|
||||
std::unique_lock<std::mutex> lock(switcher->m);
|
||||
SetMacroAbortWait(false);
|
||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||
waitHelper(&lock, GetMacro(), time);
|
||||
|
||||
return !switcher->abortMacroWait;
|
||||
return !MacroWaitShouldAbort();
|
||||
}
|
||||
|
||||
bool MacroActionWait::Save(obs_data_t *obj) const
|
||||
|
||||
@@ -62,17 +62,17 @@ MacroConditionAudio::~MacroConditionAudio()
|
||||
bool MacroConditionAudio::CheckOutputCondition()
|
||||
{
|
||||
bool ret = false;
|
||||
auto s = obs_weak_source_get_source(_audioSource.GetSource());
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
|
||||
// peak will have a value from -60 db to 0 db so we need to scale it
|
||||
double curVolume = ((double)_peak + 60) * 1.7;
|
||||
|
||||
switch (_outputCondition) {
|
||||
case OutputCondition::ABOVE:
|
||||
// peak will have a value from -60 db to 0 db
|
||||
ret = curVolume > _volume;
|
||||
break;
|
||||
case OutputCondition::BELOW:
|
||||
// peak will have a value from -60 db to 0 db
|
||||
ret = curVolume < _volume;
|
||||
break;
|
||||
default:
|
||||
@@ -84,21 +84,21 @@ bool MacroConditionAudio::CheckOutputCondition()
|
||||
|
||||
// Reset for next check
|
||||
_peak = -std::numeric_limits<float>::infinity();
|
||||
obs_source_release(s);
|
||||
if (_audioSource.GetType() == SourceSelection::Type::VARIABLE) {
|
||||
ResetVolmeter();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckVolumeCondition()
|
||||
{
|
||||
bool ret = false;
|
||||
auto s = obs_weak_source_get_source(_audioSource.GetSource());
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
|
||||
float curVolume = obs_source_get_volume(s);
|
||||
bool muted = obs_source_muted(s);
|
||||
float curVolume = obs_source_get_volume(source);
|
||||
bool muted = obs_source_muted(source);
|
||||
|
||||
switch (_volumeCondition) {
|
||||
case VolumeCondition::ABOVE:
|
||||
@@ -126,10 +126,9 @@ bool MacroConditionAudio::CheckVolumeCondition()
|
||||
}
|
||||
|
||||
SetTempVarValue("configured_volume", std::to_string(curVolume));
|
||||
SetTempVarValue("muted", muted ? "true" : "false");
|
||||
SetTempVarValue("muted", (source && muted) ? "true" : "false");
|
||||
|
||||
obs_source_release(s);
|
||||
return ret;
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckSyncOffset()
|
||||
@@ -139,8 +138,9 @@ bool MacroConditionAudio::CheckSyncOffset()
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
auto s = obs_weak_source_get_source(_audioSource.GetSource());
|
||||
auto curOffset = obs_source_get_sync_offset(s) / nsPerMs;
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
auto curOffset = obs_source_get_sync_offset(source) / nsPerMs;
|
||||
if (_outputCondition == OutputCondition::ABOVE) {
|
||||
ret = curOffset > _syncOffset;
|
||||
} else {
|
||||
@@ -148,8 +148,7 @@ bool MacroConditionAudio::CheckSyncOffset()
|
||||
}
|
||||
SetVariableValue(std::to_string(curOffset));
|
||||
SetTempVarValue("sync_offset", std::to_string(curOffset));
|
||||
obs_source_release(s);
|
||||
return ret;
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckMonitor()
|
||||
@@ -159,13 +158,13 @@ bool MacroConditionAudio::CheckMonitor()
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
auto s = obs_weak_source_get_source(_audioSource.GetSource());
|
||||
ret = obs_source_get_monitoring_type(s) == _monitorType;
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
ret = obs_source_get_monitoring_type(source) == _monitorType;
|
||||
SetVariableValue("");
|
||||
SetTempVarValue("monitor",
|
||||
std::to_string(obs_source_get_monitoring_type(s)));
|
||||
obs_source_release(s);
|
||||
return ret;
|
||||
std::to_string(obs_source_get_monitoring_type(source)));
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckBalance()
|
||||
@@ -175,8 +174,9 @@ bool MacroConditionAudio::CheckBalance()
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
auto s = obs_weak_source_get_source(_audioSource.GetSource());
|
||||
auto curBalance = obs_source_get_balance_value(s);
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
auto curBalance = obs_source_get_balance_value(source);
|
||||
if (_outputCondition == OutputCondition::ABOVE) {
|
||||
ret = curBalance > _balance;
|
||||
} else {
|
||||
@@ -184,8 +184,7 @@ bool MacroConditionAudio::CheckBalance()
|
||||
}
|
||||
SetVariableValue(std::to_string(curBalance));
|
||||
SetTempVarValue("balance", std::to_string(curBalance));
|
||||
obs_source_release(s);
|
||||
return ret;
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckCondition()
|
||||
@@ -239,13 +238,12 @@ obs_volmeter_t *AddVolmeterToSource(MacroConditionAudio *entry,
|
||||
obs_volmeter_t *volmeter = obs_volmeter_create(OBS_FADER_LOG);
|
||||
obs_volmeter_add_callback(volmeter, MacroConditionAudio::SetVolumeLevel,
|
||||
entry);
|
||||
obs_source_t *as = obs_weak_source_get_source(source);
|
||||
if (!obs_volmeter_attach_source(volmeter, as)) {
|
||||
const char *name = obs_source_get_name(as);
|
||||
OBSSourceAutoRelease audioSource = obs_weak_source_get_source(source);
|
||||
if (!obs_volmeter_attach_source(volmeter, audioSource)) {
|
||||
const char *name = obs_source_get_name(audioSource);
|
||||
blog(LOG_WARNING, "failed to attach volmeter to source %s",
|
||||
name);
|
||||
}
|
||||
obs_source_release(as);
|
||||
|
||||
return volmeter;
|
||||
}
|
||||
@@ -455,10 +453,9 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
void MacroConditionAudioEdit::UpdateVolmeterSource()
|
||||
{
|
||||
delete _volMeter;
|
||||
obs_source_t *soruce = obs_weak_source_get_source(
|
||||
OBSSourceAutoRelease soruce = obs_weak_source_get_source(
|
||||
_entryData->_audioSource.GetSource());
|
||||
_volMeter = new VolControl(soruce);
|
||||
obs_source_release(soruce);
|
||||
_volMeter = new VolControl(soruce.Get());
|
||||
|
||||
QLayout *layout = this->layout();
|
||||
layout->addWidget(_volMeter);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-condition-cursor.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "platform-funcs.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -61,13 +60,15 @@ bool MacroConditionCursor::CheckCondition()
|
||||
std::to_string(cursorPos.second));
|
||||
break;
|
||||
case Condition::MOVING:
|
||||
ret = switcher->cursorPosChanged;
|
||||
ret = cursorPos.first != _lastCursorPosition.first ||
|
||||
cursorPos.second != _lastCursorPosition.second;
|
||||
break;
|
||||
case Condition::CLICK:
|
||||
ret = CheckClick();
|
||||
break;
|
||||
}
|
||||
_lastCheckTime = std::chrono::high_resolution_clock::now();
|
||||
_lastCursorPosition = cursorPos;
|
||||
|
||||
if (GetVariableValue().empty()) {
|
||||
SetVariableValue(ret ? "true" : "false");
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
private:
|
||||
bool CheckClick();
|
||||
std::chrono::high_resolution_clock::time_point _lastCheckTime{};
|
||||
std::pair<int, int> _lastCursorPosition;
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
|
||||
@@ -638,10 +638,24 @@ void MacroConditionDateEdit::AdvancedSettingsToggleClicked()
|
||||
{
|
||||
auto lock = LockContext();
|
||||
_entryData->_dayOfWeekCheck = !_entryData->_dayOfWeekCheck;
|
||||
_entryData->_condition = MacroConditionDate::Condition::AT;
|
||||
}
|
||||
_condition->setCurrentIndex(0);
|
||||
_weekCondition->setCurrentIndex(0);
|
||||
|
||||
switch (_entryData->_condition) {
|
||||
case MacroConditionDate::Condition::BETWEEN:
|
||||
case MacroConditionDate::Condition::PATTERN:
|
||||
_condition->setCurrentIndex(0);
|
||||
_weekCondition->setCurrentIndex(0);
|
||||
break;
|
||||
case MacroConditionDate::Condition::AT:
|
||||
case MacroConditionDate::Condition::AFTER:
|
||||
case MacroConditionDate::Condition::BEFORE:
|
||||
_weekCondition->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_condition));
|
||||
_condition->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_condition));
|
||||
break;
|
||||
}
|
||||
|
||||
SetWidgetStatus();
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
|
||||
@@ -1,84 +1,24 @@
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "macro-properties.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "macro-condition-scene.hpp"
|
||||
#include "section.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::map<std::string, MacroConditionInfo> &MacroConditionFactory::GetMap()
|
||||
{
|
||||
static std::map<std::string, MacroConditionInfo> _methods;
|
||||
return _methods;
|
||||
}
|
||||
|
||||
bool MacroConditionFactory::Register(const std::string &id,
|
||||
MacroConditionInfo info)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it == GetMap().end()) {
|
||||
GetMap()[id] = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<MacroCondition>
|
||||
MacroConditionFactory::Create(const std::string &id, Macro *m)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._createFunc(m);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidget *
|
||||
MacroConditionFactory::CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroCondition> cond)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._createWidgetFunc(parent, cond);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string MacroConditionFactory::GetConditionName(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._name;
|
||||
}
|
||||
return "unknown condition";
|
||||
}
|
||||
|
||||
std::string MacroConditionFactory::GetIdByName(const QString &name)
|
||||
{
|
||||
for (auto it : GetMap()) {
|
||||
if (name == obs_module_text(it.second._name.c_str())) {
|
||||
return it.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MacroConditionFactory::UsesDurationModifier(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._useDurationModifier;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void populateLogicSelection(QComboBox *list, bool root = false)
|
||||
{
|
||||
if (root) {
|
||||
for (auto entry : MacroCondition::logicTypes) {
|
||||
for (const auto &entry : MacroCondition::logicTypes) {
|
||||
if (static_cast<int>(entry.first) < logic_root_offset) {
|
||||
list->addItem(obs_module_text(
|
||||
entry.second._name.c_str()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto entry : MacroCondition::logicTypes) {
|
||||
for (const auto &entry : MacroCondition::logicTypes) {
|
||||
if (static_cast<int>(entry.first) >=
|
||||
logic_root_offset) {
|
||||
list->addItem(obs_module_text(
|
||||
@@ -90,7 +30,7 @@ static inline void populateLogicSelection(QComboBox *list, bool root = false)
|
||||
|
||||
static inline void populateConditionSelection(QComboBox *list)
|
||||
{
|
||||
for (auto &[_, condition] :
|
||||
for (const auto &[_, condition] :
|
||||
MacroConditionFactory::GetConditionTypes()) {
|
||||
QString entry(obs_module_text(condition._name.c_str()));
|
||||
if (list->findText(entry) == -1) {
|
||||
@@ -179,7 +119,7 @@ void DurationModifierEdit::Collapse(bool collapse)
|
||||
MacroConditionEdit::MacroConditionEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroCondition> *entryData,
|
||||
const std::string &id, bool root)
|
||||
: MacroSegmentEdit(switcher->macroProperties._highlightConditions,
|
||||
: MacroSegmentEdit(GetGlobalMacroProperties()._highlightConditions,
|
||||
parent),
|
||||
_logicSelection(new QComboBox()),
|
||||
_conditionSelection(new FilterComboBox()),
|
||||
|
||||
@@ -1,38 +1,12 @@
|
||||
#pragma once
|
||||
#include "macro-condition.hpp"
|
||||
#include "macro-condition-factory.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace advss {
|
||||
|
||||
struct MacroConditionInfo {
|
||||
using TCreateMethod = std::shared_ptr<MacroCondition> (*)(Macro *m);
|
||||
using TCreateWidgetMethod =
|
||||
QWidget *(*)(QWidget *parent, std::shared_ptr<MacroCondition>);
|
||||
TCreateMethod _createFunc = nullptr;
|
||||
TCreateWidgetMethod _createWidgetFunc = nullptr;
|
||||
std::string _name;
|
||||
bool _useDurationModifier = true;
|
||||
};
|
||||
|
||||
class MacroConditionFactory {
|
||||
public:
|
||||
MacroConditionFactory() = delete;
|
||||
static bool Register(const std::string &, MacroConditionInfo);
|
||||
static std::shared_ptr<MacroCondition> Create(const std::string &,
|
||||
Macro *m);
|
||||
static QWidget *CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroCondition>);
|
||||
static auto GetConditionTypes() { return GetMap(); }
|
||||
static std::string GetConditionName(const std::string &);
|
||||
static std::string GetIdByName(const QString &name);
|
||||
static bool UsesDurationModifier(const std::string &id);
|
||||
|
||||
private:
|
||||
static std::map<std::string, MacroConditionInfo> &GetMap();
|
||||
};
|
||||
|
||||
class DurationModifierEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
66
src/macro-core/macro-condition-factory.cpp
Normal file
66
src/macro-core/macro-condition-factory.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "macro-condition-factory.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::map<std::string, MacroConditionInfo> &MacroConditionFactory::GetMap()
|
||||
{
|
||||
static std::map<std::string, MacroConditionInfo> _methods;
|
||||
return _methods;
|
||||
}
|
||||
|
||||
bool MacroConditionFactory::Register(const std::string &id,
|
||||
MacroConditionInfo info)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it == GetMap().end()) {
|
||||
GetMap()[id] = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<MacroCondition>
|
||||
MacroConditionFactory::Create(const std::string &id, Macro *m)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._create(m);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidget *
|
||||
MacroConditionFactory::CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroCondition> cond)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._createWidget(parent, cond);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string MacroConditionFactory::GetConditionName(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._name;
|
||||
}
|
||||
return "unknown condition";
|
||||
}
|
||||
|
||||
std::string MacroConditionFactory::GetIdByName(const QString &name)
|
||||
{
|
||||
for (auto it : GetMap()) {
|
||||
if (name == obs_module_text(it.second._name.c_str())) {
|
||||
return it.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MacroConditionFactory::UsesDurationModifier(const std::string &id)
|
||||
{
|
||||
if (auto it = GetMap().find(id); it != GetMap().end()) {
|
||||
return it->second._useDurationModifier;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
35
src/macro-core/macro-condition-factory.hpp
Normal file
35
src/macro-core/macro-condition-factory.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "macro-condition.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace advss {
|
||||
|
||||
struct MacroConditionInfo {
|
||||
using CreateCondition = std::shared_ptr<MacroCondition> (*)(Macro *m);
|
||||
using CreateConditionWidget =
|
||||
QWidget *(*)(QWidget *parent, std::shared_ptr<MacroCondition>);
|
||||
CreateCondition _create = nullptr;
|
||||
CreateConditionWidget _createWidget = nullptr;
|
||||
std::string _name;
|
||||
bool _useDurationModifier = true;
|
||||
};
|
||||
|
||||
class MacroConditionFactory {
|
||||
public:
|
||||
MacroConditionFactory() = delete;
|
||||
static bool Register(const std::string &, MacroConditionInfo);
|
||||
static std::shared_ptr<MacroCondition> Create(const std::string &,
|
||||
Macro *m);
|
||||
static QWidget *CreateWidget(const std::string &id, QWidget *parent,
|
||||
std::shared_ptr<MacroCondition>);
|
||||
static auto GetConditionTypes() { return GetMap(); }
|
||||
static std::string GetConditionName(const std::string &);
|
||||
static std::string GetIdByName(const QString &name);
|
||||
static bool UsesDurationModifier(const std::string &id);
|
||||
|
||||
private:
|
||||
static std::map<std::string, MacroConditionInfo> &GetMap();
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "macro-condition-file.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "curl-helper.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QFileDialog>
|
||||
@@ -28,16 +28,16 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
static std::string getRemoteData(std::string &url)
|
||||
{
|
||||
std::string readBuffer;
|
||||
switcher->curl.SetOpt(CURLOPT_URL, url.c_str());
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
switcher->curl.SetOpt(CURLOPT_WRITEDATA, &readBuffer);
|
||||
CurlHelper::SetOpt(CURLOPT_URL, url.c_str());
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
CurlHelper::SetOpt(CURLOPT_WRITEDATA, &readBuffer);
|
||||
// Set timeout to at least one second
|
||||
int timeout = switcher->interval / 1000;
|
||||
int timeout = GetIntervalValue() / 1000;
|
||||
if (timeout == 0) {
|
||||
timeout = 1;
|
||||
}
|
||||
switcher->curl.SetOpt(CURLOPT_TIMEOUT, 1);
|
||||
switcher->curl.Perform();
|
||||
CurlHelper::SetOpt(CURLOPT_TIMEOUT, 1);
|
||||
CurlHelper::Perform();
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ const static std::map<MacroConditionMacro::Type, std::string>
|
||||
"AdvSceneSwitcher.condition.macro.type.actionDisabled"},
|
||||
{MacroConditionMacro::Type::ACTION_ENABLED,
|
||||
"AdvSceneSwitcher.condition.macro.type.actionEnabled"},
|
||||
{MacroConditionMacro::Type::PAUSED,
|
||||
"AdvSceneSwitcher.condition.macro.type.paused"},
|
||||
};
|
||||
|
||||
const static std::map<MacroConditionMacro::CounterCondition, std::string>
|
||||
@@ -75,6 +77,8 @@ bool MacroConditionMacro::CheckMultiStateCondition()
|
||||
}
|
||||
}
|
||||
|
||||
SetTempVarValue("matchedCount", std::to_string(matchedCount));
|
||||
|
||||
switch (_multiSateCondition) {
|
||||
case MacroConditionMacro::MultiStateCondition::BELOW:
|
||||
return matchedCount < _multiSateCount;
|
||||
@@ -107,6 +111,16 @@ bool MacroConditionMacro::CheckActionStateCondition()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroConditionMacro::CheckPauseState()
|
||||
{
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return macro->Paused();
|
||||
}
|
||||
|
||||
bool MacroConditionMacro::CheckCountCondition()
|
||||
{
|
||||
auto macro = _macro.GetMacro();
|
||||
@@ -114,6 +128,8 @@ bool MacroConditionMacro::CheckCountCondition()
|
||||
return false;
|
||||
}
|
||||
|
||||
SetTempVarValue("runCount", std::to_string(macro->RunCount()));
|
||||
|
||||
switch (_counterCondition) {
|
||||
case CounterCondition::BELOW:
|
||||
return macro->RunCount() < _count;
|
||||
@@ -140,6 +156,8 @@ bool MacroConditionMacro::CheckCondition()
|
||||
case Type::ACTION_DISABLED:
|
||||
case Type::ACTION_ENABLED:
|
||||
return CheckActionStateCondition();
|
||||
case Type::PAUSED:
|
||||
return CheckPauseState();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -193,7 +211,7 @@ bool MacroConditionMacro::Load(obs_data_t *obj)
|
||||
|
||||
bool MacroConditionMacro::PostLoad()
|
||||
{
|
||||
return MacroRefCondition::PostLoad() &&
|
||||
return MacroCondition::PostLoad() && MacroRefCondition::PostLoad() &&
|
||||
MultiMacroRefCondtition::PostLoad();
|
||||
}
|
||||
|
||||
@@ -202,6 +220,45 @@ std::string MacroConditionMacro::GetShortDesc() const
|
||||
return _macro.Name();
|
||||
}
|
||||
|
||||
void MacroConditionMacro::SetType(Type type)
|
||||
{
|
||||
_type = type;
|
||||
SetupTempVars();
|
||||
}
|
||||
|
||||
void MacroConditionMacro::SetupTempVars()
|
||||
{
|
||||
MacroCondition::SetupTempVars();
|
||||
switch (_type) {
|
||||
case Type::COUNT:
|
||||
AddTempvar(
|
||||
"runCount",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.macro.runCount"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.macro.runCount.description"));
|
||||
break;
|
||||
case Type::STATE:
|
||||
break;
|
||||
case Type::MULTI_STATE:
|
||||
AddTempvar(
|
||||
"matchedCount",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.macro.matchedCount"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.macro.matchedCount.description"));
|
||||
break;
|
||||
case Type::ACTION_DISABLED:
|
||||
break;
|
||||
case Type::ACTION_ENABLED:
|
||||
break;
|
||||
case Type::PAUSED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void populateTypeSelection(QComboBox *list)
|
||||
{
|
||||
for (auto entry : macroConditionTypes) {
|
||||
@@ -335,7 +392,10 @@ void MacroConditionMacroEdit::ClearLayouts()
|
||||
|
||||
void MacroConditionMacroEdit::SetupWidgets()
|
||||
{
|
||||
switch (_entryData->_type) {
|
||||
SetWidgetVisibility();
|
||||
ClearLayouts();
|
||||
|
||||
switch (_entryData->GetType()) {
|
||||
case MacroConditionMacro::Type::COUNT:
|
||||
SetupCountWidgets();
|
||||
break;
|
||||
@@ -351,6 +411,9 @@ void MacroConditionMacroEdit::SetupWidgets()
|
||||
case MacroConditionMacro::Type::ACTION_ENABLED:
|
||||
SetupActionStateWidgets(true);
|
||||
break;
|
||||
case MacroConditionMacro::Type::PAUSED:
|
||||
SetupPauseWidgets();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -358,38 +421,24 @@ void MacroConditionMacroEdit::SetupWidgets()
|
||||
|
||||
void MacroConditionMacroEdit::SetupStateWidgets()
|
||||
{
|
||||
SetWidgetVisibility();
|
||||
ClearLayouts();
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{macros}}", _macros},
|
||||
};
|
||||
PlaceWidgets(
|
||||
obs_module_text("AdvSceneSwitcher.condition.macro.state.entry"),
|
||||
_settingsLine1, widgetPlaceholders);
|
||||
_settingsLine1, {{"{{macros}}", _macros}});
|
||||
}
|
||||
|
||||
void MacroConditionMacroEdit::SetupMultiStateWidgets()
|
||||
{
|
||||
SetWidgetVisibility();
|
||||
ClearLayouts();
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{multiStateConditions}}", _multiStateConditions},
|
||||
{"{{multiStateCount}}", _multiStateCount},
|
||||
};
|
||||
PlaceWidgets(
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.condition.macro.multistate.entry"),
|
||||
_settingsLine1, widgetPlaceholders);
|
||||
_settingsLine1,
|
||||
{{"{{multiStateConditions}}", _multiStateConditions},
|
||||
{"{{multiStateCount}}", _multiStateCount}});
|
||||
}
|
||||
|
||||
void MacroConditionMacroEdit::SetupCountWidgets()
|
||||
{
|
||||
SetWidgetVisibility();
|
||||
ClearLayouts();
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
const std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{macros}}", _macros},
|
||||
{"{{conditions}}", _counterConditions},
|
||||
{"{{count}}", _count},
|
||||
@@ -408,9 +457,6 @@ void MacroConditionMacroEdit::SetupCountWidgets()
|
||||
|
||||
void MacroConditionMacroEdit::SetupActionStateWidgets(bool enable)
|
||||
{
|
||||
SetWidgetVisibility();
|
||||
ClearLayouts();
|
||||
|
||||
PlaceWidgets(
|
||||
obs_module_text(
|
||||
enable ? "AdvSceneSwitcher.condition.macro.actionState.enabled.entry"
|
||||
@@ -419,35 +465,49 @@ void MacroConditionMacroEdit::SetupActionStateWidgets(bool enable)
|
||||
{{"{{macros}}", _macros}, {"{{actionIndex}}", _actionIndex}});
|
||||
}
|
||||
|
||||
void MacroConditionMacroEdit::SetupPauseWidgets()
|
||||
{
|
||||
PlaceWidgets(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.macro.paused.entry"),
|
||||
_settingsLine1, {{"{{macros}}", _macros}});
|
||||
}
|
||||
|
||||
void MacroConditionMacroEdit::SetWidgetVisibility()
|
||||
{
|
||||
_macros->setVisible(
|
||||
_entryData->_type == MacroConditionMacro::Type::COUNT ||
|
||||
_entryData->_type == MacroConditionMacro::Type::STATE ||
|
||||
_entryData->_type ==
|
||||
_entryData->GetType() == MacroConditionMacro::Type::COUNT ||
|
||||
_entryData->GetType() == MacroConditionMacro::Type::STATE ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_DISABLED ||
|
||||
_entryData->_type == MacroConditionMacro::Type::ACTION_ENABLED);
|
||||
_counterConditions->setVisible(_entryData->_type ==
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_ENABLED ||
|
||||
_entryData->GetType() == MacroConditionMacro::Type::PAUSED);
|
||||
_counterConditions->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::COUNT);
|
||||
_count->setVisible(_entryData->_type ==
|
||||
_count->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::COUNT);
|
||||
_currentCount->setVisible(_entryData->_type ==
|
||||
_currentCount->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::COUNT);
|
||||
_resetCount->setVisible(_entryData->_type ==
|
||||
_resetCount->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::COUNT);
|
||||
_macroList->setVisible(_entryData->_type ==
|
||||
_macroList->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::MULTI_STATE);
|
||||
_multiStateConditions->setVisible(
|
||||
_entryData->_type == MacroConditionMacro::Type::MULTI_STATE);
|
||||
_multiStateCount->setVisible(_entryData->_type ==
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::MULTI_STATE);
|
||||
_multiStateCount->setVisible(_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::MULTI_STATE);
|
||||
_actionIndex->setVisible(
|
||||
_entryData->_type ==
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_DISABLED ||
|
||||
_entryData->_type == MacroConditionMacro::Type::ACTION_ENABLED);
|
||||
if (_entryData->_type == MacroConditionMacro::Type::MULTI_STATE ||
|
||||
_entryData->_type == MacroConditionMacro::Type::ACTION_DISABLED ||
|
||||
_entryData->_type == MacroConditionMacro::Type::ACTION_ENABLED) {
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_ENABLED);
|
||||
if (_entryData->GetType() == MacroConditionMacro::Type::MULTI_STATE ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_DISABLED ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionMacro::Type::ACTION_ENABLED ||
|
||||
_entryData->GetType() == MacroConditionMacro::Type::PAUSED) {
|
||||
_pausedWarning->hide();
|
||||
}
|
||||
|
||||
@@ -463,7 +523,7 @@ void MacroConditionMacroEdit::UpdateEntryData()
|
||||
|
||||
SetupWidgets();
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
_types->setCurrentIndex(static_cast<int>(_entryData->_type));
|
||||
_types->setCurrentIndex(static_cast<int>(_entryData->GetType()));
|
||||
_counterConditions->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_counterCondition));
|
||||
_count->SetValue(_entryData->_count);
|
||||
@@ -535,7 +595,7 @@ void MacroConditionMacroEdit::TypeChanged(int type)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_type = static_cast<MacroConditionMacro::Type>(type);
|
||||
_entryData->SetType(static_cast<MacroConditionMacro::Type>(type));
|
||||
SetupWidgets();
|
||||
}
|
||||
|
||||
@@ -571,7 +631,8 @@ void MacroConditionMacroEdit::UpdatePaused()
|
||||
auto macro = _entryData->_macro.GetMacro();
|
||||
_pausedWarning->setVisible(
|
||||
_entryData &&
|
||||
_entryData->_type != MacroConditionMacro::Type::MULTI_STATE &&
|
||||
_entryData->GetType() !=
|
||||
MacroConditionMacro::Type::MULTI_STATE &&
|
||||
macro && macro->Paused());
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
|
||||
@@ -39,8 +39,10 @@ public:
|
||||
MULTI_STATE,
|
||||
ACTION_DISABLED,
|
||||
ACTION_ENABLED,
|
||||
PAUSED,
|
||||
};
|
||||
Type _type = Type::STATE;
|
||||
void SetType(Type);
|
||||
Type GetType() const { return _type; }
|
||||
|
||||
enum class CounterCondition {
|
||||
BELOW,
|
||||
@@ -64,7 +66,11 @@ private:
|
||||
bool CheckStateCondition();
|
||||
bool CheckMultiStateCondition();
|
||||
bool CheckActionStateCondition();
|
||||
bool CheckPauseState();
|
||||
|
||||
void SetupTempVars();
|
||||
|
||||
Type _type = Type::STATE;
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
@@ -128,6 +134,7 @@ private:
|
||||
void SetupMultiStateWidgets();
|
||||
void SetupCountWidgets();
|
||||
void SetupActionStateWidgets(bool enable);
|
||||
void SetupPauseWidgets();
|
||||
void SetWidgetVisibility();
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "macro-condition-media.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "scene-switch-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -148,26 +150,20 @@ bool MacroConditionMedia::CheckMediaMatch()
|
||||
if (!_source.GetSource()) {
|
||||
return false;
|
||||
}
|
||||
bool match = false;
|
||||
bool matched = CheckState() && CheckTime();
|
||||
|
||||
if (matched && !(_onlyMatchOnChagne && _alreadyMatched)) {
|
||||
match = true;
|
||||
}
|
||||
_alreadyMatched = matched;
|
||||
|
||||
// reset for next check
|
||||
_stopped = false;
|
||||
_ended = false;
|
||||
_next = false;
|
||||
|
||||
return match;
|
||||
return matched;
|
||||
}
|
||||
|
||||
void MacroConditionMedia::HandleSceneChange()
|
||||
{
|
||||
UpdateMediaSourcesOfSceneList();
|
||||
_lastConfigureScene = switcher->currentScene;
|
||||
_lastConfigureScene = GetCurrentScene();
|
||||
}
|
||||
|
||||
bool MacroConditionMedia::CheckCondition()
|
||||
@@ -194,7 +190,7 @@ bool MacroConditionMedia::CheckCondition()
|
||||
break;
|
||||
}
|
||||
|
||||
if (_lastConfigureScene != switcher->currentScene) {
|
||||
if (_lastConfigureScene != GetCurrentScene()) {
|
||||
HandleSceneChange();
|
||||
}
|
||||
|
||||
@@ -210,7 +206,6 @@ bool MacroConditionMedia::Save(obs_data_t *obj) const
|
||||
obs_data_set_int(obj, "state", static_cast<int>(_state));
|
||||
obs_data_set_int(obj, "restriction", static_cast<int>(_restriction));
|
||||
_time.Save(obj);
|
||||
obs_data_set_bool(obj, "matchOnChagne", _onlyMatchOnChagne);
|
||||
obs_data_set_int(obj, "version", 0);
|
||||
return true;
|
||||
}
|
||||
@@ -268,7 +263,6 @@ bool MacroConditionMedia::Load(obs_data_t *obj)
|
||||
_restriction = static_cast<MacroConditionMedia::Time>(
|
||||
obs_data_get_int(obj, "restriction"));
|
||||
_time.Load(obj);
|
||||
_onlyMatchOnChagne = obs_data_get_bool(obj, "matchOnChagne");
|
||||
|
||||
if (_sourceType == Type::SOURCE) {
|
||||
obs_source_t *mediasource =
|
||||
@@ -408,9 +402,7 @@ MacroConditionMediaEdit::MacroConditionMediaEdit(
|
||||
_sources(new SourceSelectionWidget(this, QStringList(), true)),
|
||||
_states(new QComboBox()),
|
||||
_timeRestrictions(new QComboBox()),
|
||||
_time(new DurationSelection()),
|
||||
_onChange(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.media.matchOnChange")))
|
||||
_time(new DurationSelection())
|
||||
{
|
||||
_states->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.media.inconsistencyInfo"));
|
||||
@@ -432,14 +424,12 @@ MacroConditionMediaEdit::MacroConditionMediaEdit(
|
||||
this, SLOT(TimeRestrictionChanged(int)));
|
||||
QWidget::connect(_time, SIGNAL(DurationChanged(const Duration &)), this,
|
||||
SLOT(TimeChanged(const Duration &)));
|
||||
QWidget::connect(_onChange, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(OnChangeChanged(int)));
|
||||
|
||||
populateSourceTypes(_sourceTypes);
|
||||
populateMediaStates(_states);
|
||||
populateMediaTimes(_timeRestrictions);
|
||||
|
||||
QHBoxLayout *entryLayout = new QHBoxLayout;
|
||||
auto layout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{sourceTypes}}", _sourceTypes},
|
||||
{"{{mediaSources}}", _sources},
|
||||
@@ -449,11 +439,8 @@ MacroConditionMediaEdit::MacroConditionMediaEdit(
|
||||
{"{{time}}", _time},
|
||||
};
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.condition.media.entry"),
|
||||
entryLayout, widgetPlaceholders);
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(entryLayout);
|
||||
mainLayout->addWidget(_onChange);
|
||||
setLayout(mainLayout);
|
||||
layout, widgetPlaceholders);
|
||||
setLayout(layout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
@@ -572,28 +559,12 @@ void MacroConditionMediaEdit::TimeChanged(const Duration &dur)
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionMediaEdit::OnChangeChanged(int value)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_onlyMatchOnChagne = value;
|
||||
if (_entryData->_sourceType != MacroConditionMedia::Type::SOURCE) {
|
||||
_entryData->UpdateMediaSourcesOfSceneList();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionMediaEdit::SetWidgetVisibility()
|
||||
{
|
||||
_sources->setVisible(_entryData->_sourceType ==
|
||||
MacroConditionMedia::Type::SOURCE);
|
||||
_scenes->setVisible(_entryData->_sourceType !=
|
||||
MacroConditionMedia::Type::SOURCE);
|
||||
if (!_onChange->isChecked()) {
|
||||
_onChange->hide();
|
||||
}
|
||||
}
|
||||
|
||||
static int getIdxFromMediaState(MacroConditionMedia::State state)
|
||||
@@ -625,7 +596,6 @@ void MacroConditionMediaEdit::UpdateEntryData()
|
||||
MacroConditionMedia::Time::TIME_RESTRICTION_NONE) {
|
||||
_time->setDisabled(true);
|
||||
}
|
||||
_onChange->setChecked(_entryData->_onlyMatchOnChagne);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ public:
|
||||
OBSWeakSource _rawSource = nullptr;
|
||||
std::vector<MacroConditionMedia> _sourceGroup;
|
||||
Duration _time;
|
||||
bool _onlyMatchOnChagne = false;
|
||||
|
||||
private:
|
||||
bool CheckTime();
|
||||
@@ -84,9 +83,7 @@ private:
|
||||
bool _stopped = false;
|
||||
bool _ended = false;
|
||||
bool _next = false;
|
||||
// TODO: Remove _alreadyMatched as it does not make much sense when
|
||||
// time restrictions for macro conditions are available.
|
||||
bool _alreadyMatched = false;
|
||||
|
||||
// Workaround to enable use of "ended" to specify end of VLC playlist
|
||||
bool _previousStateEnded = false;
|
||||
// Used to keep track of scene changes
|
||||
@@ -119,7 +116,6 @@ private slots:
|
||||
void StateChanged(int index);
|
||||
void TimeRestrictionChanged(int index);
|
||||
void TimeChanged(const Duration &seconds);
|
||||
void OnChangeChanged(int);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
@@ -130,7 +126,6 @@ protected:
|
||||
QComboBox *_states;
|
||||
QComboBox *_timeRestrictions;
|
||||
DurationSelection *_time;
|
||||
QCheckBox *_onChange;
|
||||
std::shared_ptr<MacroConditionMedia> _entryData;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "macro-condition-plugin-state.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -33,7 +34,7 @@ const static std::map<MacroConditionPluginState::Condition, std::string>
|
||||
MacroConditionPluginState::~MacroConditionPluginState()
|
||||
{
|
||||
if (_condition == Condition::OBS_SHUTDOWN) {
|
||||
switcher->shutdownConditionCount--;
|
||||
GetShutdownConditionCount()--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +42,15 @@ bool MacroConditionPluginState::CheckCondition()
|
||||
{
|
||||
switch (_condition) {
|
||||
case Condition::PLUGIN_SCENE_CHANGE:
|
||||
return switcher->macroSceneSwitched;
|
||||
return MacroSwitchedScene();
|
||||
case Condition::PLUGIN_RUNNING:
|
||||
return true;
|
||||
case Condition::OBS_SHUTDOWN:
|
||||
return switcher->obsIsShuttingDown;
|
||||
return OBSIsShuttingDown();
|
||||
case Condition::PLUGIN_START:
|
||||
return switcher->firstInterval;
|
||||
return IsFirstInterval();
|
||||
case Condition::PLUGIN_RESTART:
|
||||
return switcher->firstIntervalAfterStop;
|
||||
return IsFirstIntervalAfterStop();
|
||||
case Condition::SCENE_COLLECTION_CHANGE:
|
||||
if (_firstCheckAfterSceneCollectionChange) {
|
||||
_firstCheckAfterSceneCollectionChange = false;
|
||||
@@ -83,25 +84,33 @@ bool MacroConditionPluginState::Load(obs_data_t *obj)
|
||||
obs_data_get_int(obj, "condition"));
|
||||
switch (oldValue) {
|
||||
case PluginStateCondition::SCENE_SWITCHED:
|
||||
_condition = Condition::PLUGIN_SCENE_CHANGE;
|
||||
SetCondition(Condition::PLUGIN_SCENE_CHANGE);
|
||||
break;
|
||||
case PluginStateCondition::RUNNING:
|
||||
_condition = Condition::PLUGIN_RUNNING;
|
||||
SetCondition(Condition::PLUGIN_RUNNING);
|
||||
break;
|
||||
case PluginStateCondition::SHUTDOWN:
|
||||
_condition = Condition::OBS_SHUTDOWN;
|
||||
SetCondition(Condition::OBS_SHUTDOWN);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_condition = static_cast<Condition>(
|
||||
obs_data_get_int(obj, "condition"));
|
||||
}
|
||||
if (_condition == Condition::OBS_SHUTDOWN) {
|
||||
switcher->shutdownConditionCount++;
|
||||
SetCondition(static_cast<Condition>(
|
||||
obs_data_get_int(obj, "condition")));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroConditionPluginState::SetCondition(Condition newValue)
|
||||
{
|
||||
if (_condition == Condition::OBS_SHUTDOWN) {
|
||||
GetShutdownConditionCount()--;
|
||||
}
|
||||
if (newValue == Condition::OBS_SHUTDOWN) {
|
||||
GetShutdownConditionCount()++;
|
||||
}
|
||||
_condition = newValue;
|
||||
}
|
||||
|
||||
static inline void populateConditionSelection(QComboBox *list)
|
||||
{
|
||||
for (const auto &[action, name] : pluginStateConditionTypes) {
|
||||
@@ -148,17 +157,9 @@ void MacroConditionPluginStateEdit::ConditionChanged(int idx)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
if (_entryData->_condition ==
|
||||
MacroConditionPluginState::Condition::OBS_SHUTDOWN) {
|
||||
switcher->shutdownConditionCount--;
|
||||
}
|
||||
_entryData->_condition =
|
||||
_entryData->SetCondition(
|
||||
static_cast<MacroConditionPluginState::Condition>(
|
||||
_condition->itemData(idx).toInt());
|
||||
if (_entryData->_condition ==
|
||||
MacroConditionPluginState::Condition::OBS_SHUTDOWN) {
|
||||
switcher->shutdownConditionCount++;
|
||||
}
|
||||
_condition->itemData(idx).toInt()));
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
@@ -168,15 +169,15 @@ void MacroConditionPluginStateEdit::UpdateEntryData()
|
||||
return;
|
||||
}
|
||||
|
||||
_condition->setCurrentIndex(
|
||||
_condition->findData(static_cast<int>(_entryData->_condition)));
|
||||
_condition->setCurrentIndex(_condition->findData(
|
||||
static_cast<int>(_entryData->GetCondition())));
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionPluginStateEdit::SetWidgetVisibility()
|
||||
{
|
||||
_shutdownLimitation->setVisible(
|
||||
_entryData->_condition ==
|
||||
_entryData->GetCondition() ==
|
||||
MacroConditionPluginState::Condition::OBS_SHUTDOWN);
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
|
||||
@@ -26,10 +26,11 @@ public:
|
||||
SCENE_COLLECTION_CHANGE,
|
||||
PLUGIN_SCENE_CHANGE,
|
||||
};
|
||||
|
||||
Condition _condition = Condition::PLUGIN_SCENE_CHANGE;
|
||||
void SetCondition(Condition);
|
||||
Condition GetCondition() const { return _condition; }
|
||||
|
||||
private:
|
||||
Condition _condition = Condition::PLUGIN_SCENE_CHANGE;
|
||||
bool _firstCheckAfterSceneCollectionChange = true;
|
||||
|
||||
const static uint32_t _version;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-condition-process.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "platform-funcs.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -19,25 +18,43 @@ bool MacroConditionProcess::CheckCondition()
|
||||
QStringList runningProcesses;
|
||||
QString proc = QString::fromStdString(_process);
|
||||
GetProcessList(runningProcesses);
|
||||
std::string foregroundProcessName;
|
||||
GetForegroundProcessName(foregroundProcessName);
|
||||
|
||||
bool equals = runningProcesses.contains(proc);
|
||||
bool matches = runningProcesses.indexOf(QRegularExpression(proc)) != -1;
|
||||
bool focus = !_focus || IsInFocus(proc);
|
||||
SetVariableValue(foregroundProcessName);
|
||||
|
||||
if (IsReferencedInVars()) {
|
||||
std::string name;
|
||||
GetForegroundProcessName(name);
|
||||
SetVariableValue(name);
|
||||
if (!_regex.Enabled()) {
|
||||
if (runningProcesses.contains(proc) &&
|
||||
(!_checkFocus || IsInFocus(proc))) {
|
||||
SetTempVarValue("name", proc.toStdString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return (equals || matches) && focus;
|
||||
auto matchIndex = runningProcesses.indexOf(QRegularExpression(proc));
|
||||
if (matchIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
if (!_checkFocus) {
|
||||
SetTempVarValue("name",
|
||||
runningProcesses.at(matchIndex).toStdString());
|
||||
return true;
|
||||
}
|
||||
if (!IsInFocus(proc)) {
|
||||
return false;
|
||||
}
|
||||
SetTempVarValue("name", foregroundProcessName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionProcess::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroCondition::Save(obj);
|
||||
obs_data_set_string(obj, "process", _process.c_str());
|
||||
obs_data_set_bool(obj, "focus", _focus);
|
||||
obs_data_set_bool(obj, "focus", _checkFocus);
|
||||
_regex.Save(obj);
|
||||
obs_data_set_int(obj, "version", 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,7 +62,13 @@ bool MacroConditionProcess::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_process = obs_data_get_string(obj, "process");
|
||||
_focus = obs_data_get_bool(obj, "focus");
|
||||
_checkFocus = obs_data_get_bool(obj, "focus");
|
||||
// Fall back to partial match regex as default for old version
|
||||
if (!obs_data_has_user_value(obj, "version")) {
|
||||
_regex.SetEnabled(true);
|
||||
} else {
|
||||
_regex.Load(obj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,10 +77,18 @@ std::string MacroConditionProcess::GetShortDesc() const
|
||||
return _process;
|
||||
}
|
||||
|
||||
void MacroConditionProcess::SetupTempVars()
|
||||
{
|
||||
MacroCondition::SetupTempVars();
|
||||
AddTempvar("name",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.process.name"));
|
||||
}
|
||||
|
||||
MacroConditionProcessEdit::MacroConditionProcessEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionProcess> entryData)
|
||||
: QWidget(parent),
|
||||
_processSelection(new QComboBox()),
|
||||
_regex(new RegexConfigWidget(this)),
|
||||
_focused(new QCheckBox()),
|
||||
_focusProcess(new QLabel()),
|
||||
_focusLayout(new QHBoxLayout())
|
||||
@@ -68,6 +99,8 @@ MacroConditionProcessEdit::MacroConditionProcessEdit(
|
||||
QWidget::connect(_processSelection,
|
||||
SIGNAL(currentTextChanged(const QString &)), this,
|
||||
SLOT(ProcessChanged(const QString &)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
QWidget::connect(_focused, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(FocusChanged(int)));
|
||||
QWidget::connect(&_timer, SIGNAL(timeout()), this,
|
||||
@@ -77,6 +110,7 @@ MacroConditionProcessEdit::MacroConditionProcessEdit(
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{processes}}", _processSelection},
|
||||
{"{{regex}}", _regex},
|
||||
{"{{focused}}", _focused},
|
||||
{"{{focusProcess}}", _focusProcess},
|
||||
};
|
||||
@@ -112,6 +146,18 @@ void MacroConditionProcessEdit::ProcessChanged(const QString &text)
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
||||
void MacroConditionProcessEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_regex = conf;
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionProcessEdit::FocusChanged(int state)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
@@ -119,14 +165,15 @@ void MacroConditionProcessEdit::FocusChanged(int state)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_focus = state;
|
||||
_entryData->_checkFocus = state;
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionProcessEdit::UpdateFocusProcess()
|
||||
{
|
||||
_focusProcess->setText(
|
||||
QString::fromStdString(switcher->currentForegroundProcess));
|
||||
std::string name;
|
||||
GetForegroundProcessName(name);
|
||||
_focusProcess->setText(QString::fromStdString(name));
|
||||
}
|
||||
|
||||
void MacroConditionProcessEdit::SetWidgetVisibility()
|
||||
@@ -134,7 +181,7 @@ void MacroConditionProcessEdit::SetWidgetVisibility()
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
SetLayoutVisible(_focusLayout, _entryData->_focus);
|
||||
SetLayoutVisible(_focusLayout, _entryData->_checkFocus);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
@@ -145,7 +192,8 @@ void MacroConditionProcessEdit::UpdateEntryData()
|
||||
}
|
||||
|
||||
_processSelection->setCurrentText(_entryData->_process.c_str());
|
||||
_focused->setChecked(_entryData->_focus);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
_focused->setChecked(_entryData->_checkFocus);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
@@ -20,9 +21,12 @@ public:
|
||||
}
|
||||
|
||||
std::string _process;
|
||||
bool _focus = true;
|
||||
bool _checkFocus = true;
|
||||
RegexConfig _regex = RegexConfig::PartialMatchRegexConfig();
|
||||
|
||||
private:
|
||||
void SetupTempVars();
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
@@ -45,22 +49,22 @@ public:
|
||||
|
||||
private slots:
|
||||
void ProcessChanged(const QString &text);
|
||||
void RegexChanged(RegexConfig);
|
||||
void FocusChanged(int state);
|
||||
void UpdateFocusProcess();
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
QComboBox *_processSelection;
|
||||
RegexConfigWidget *_regex;
|
||||
QCheckBox *_focused;
|
||||
QLabel *_focusProcess;
|
||||
QHBoxLayout *_focusLayout;
|
||||
QTimer _timer;
|
||||
std::shared_ptr<MacroConditionProcess> _entryData;
|
||||
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "macro-condition-recording.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace advss {
|
||||
|
||||
const std::string MacroConditionRecord::id = "recording";
|
||||
@@ -10,45 +12,81 @@ bool MacroConditionRecord::_registered = MacroConditionFactory::Register(
|
||||
{MacroConditionRecord::Create, MacroConditionRecordEdit::Create,
|
||||
"AdvSceneSwitcher.condition.record"});
|
||||
|
||||
const static std::map<RecordState, std::string> recordStates = {
|
||||
{RecordState::STOP, "AdvSceneSwitcher.condition.record.state.stop"},
|
||||
{RecordState::PAUSE, "AdvSceneSwitcher.condition.record.state.pause"},
|
||||
{RecordState::START, "AdvSceneSwitcher.condition.record.state.start"},
|
||||
const static std::map<MacroConditionRecord::Condition, std::string>
|
||||
recordStates = {
|
||||
{MacroConditionRecord::Condition::STOP,
|
||||
"AdvSceneSwitcher.condition.record.state.stop"},
|
||||
{MacroConditionRecord::Condition::PAUSE,
|
||||
"AdvSceneSwitcher.condition.record.state.pause"},
|
||||
{MacroConditionRecord::Condition::START,
|
||||
"AdvSceneSwitcher.condition.record.state.start"},
|
||||
{MacroConditionRecord::Condition::DURATION,
|
||||
"AdvSceneSwitcher.condition.record.state.duration"},
|
||||
};
|
||||
|
||||
static bool SetupRecordingTimer();
|
||||
static bool recordingTimerIsSetup = SetupRecordingTimer();
|
||||
static int currentRecordingDurationInSeconds = 0;
|
||||
|
||||
bool MacroConditionRecord::CheckCondition()
|
||||
{
|
||||
bool stateMatch = false;
|
||||
switch (_recordState) {
|
||||
case RecordState::STOP:
|
||||
stateMatch = !obs_frontend_recording_active();
|
||||
break;
|
||||
case RecordState::PAUSE:
|
||||
stateMatch = obs_frontend_recording_paused();
|
||||
break;
|
||||
case RecordState::START:
|
||||
stateMatch = obs_frontend_recording_active();
|
||||
break;
|
||||
switch (_condition) {
|
||||
case Condition::STOP:
|
||||
return !obs_frontend_recording_active();
|
||||
case Condition::PAUSE:
|
||||
return obs_frontend_recording_paused();
|
||||
case Condition::START:
|
||||
return obs_frontend_recording_active();
|
||||
case Condition::DURATION:
|
||||
SetTempVarValue(
|
||||
"durationSeconds",
|
||||
std::to_string(currentRecordingDurationInSeconds));
|
||||
return currentRecordingDurationInSeconds > _duration.Seconds();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return stateMatch;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroConditionRecord::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroCondition::Save(obj);
|
||||
obs_data_set_int(obj, "state", static_cast<int>(_recordState));
|
||||
obs_data_set_int(obj, "state", static_cast<int>(_condition));
|
||||
_duration.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionRecord::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_recordState = static_cast<RecordState>(obs_data_get_int(obj, "state"));
|
||||
_condition = static_cast<Condition>(obs_data_get_int(obj, "state"));
|
||||
_duration.Load(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroConditionRecord::SetCondition(Condition condition)
|
||||
{
|
||||
_condition = condition;
|
||||
SetupTempVars();
|
||||
}
|
||||
|
||||
void MacroConditionRecord::SetupTempVars()
|
||||
{
|
||||
MacroCondition::SetupTempVars();
|
||||
switch (_condition) {
|
||||
case Condition::DURATION:
|
||||
AddTempvar(
|
||||
"durationSeconds",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.recording.durationSeconds"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.recording.durationSeconds.description"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void populateStateSelection(QComboBox *list)
|
||||
{
|
||||
for (auto entry : recordStates) {
|
||||
@@ -58,38 +96,39 @@ static inline void populateStateSelection(QComboBox *list)
|
||||
|
||||
MacroConditionRecordEdit::MacroConditionRecordEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionRecord> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
_condition(new QComboBox(this)),
|
||||
_duration(new DurationSelection(this))
|
||||
{
|
||||
_recordState = new QComboBox();
|
||||
populateStateSelection(_condition);
|
||||
|
||||
QWidget::connect(_recordState, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(StateChanged(int)));
|
||||
|
||||
populateStateSelection(_recordState);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{recordState}}", _recordState},
|
||||
};
|
||||
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ConditionChanged(int)));
|
||||
QWidget::connect(_duration, SIGNAL(DurationChanged(const Duration &)),
|
||||
this, SLOT(DurationChanged(const Duration &)));
|
||||
|
||||
auto layout = new QHBoxLayout;
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.condition.record.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
setLayout(mainLayout);
|
||||
layout,
|
||||
{{"{{condition}}", _condition},
|
||||
{"{{duration}}", _duration}});
|
||||
setLayout(layout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroConditionRecordEdit::StateChanged(int value)
|
||||
void MacroConditionRecordEdit::ConditionChanged(int value)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_recordState = static_cast<RecordState>(value);
|
||||
_entryData->SetCondition(
|
||||
static_cast<MacroConditionRecord::Condition>(value));
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionRecordEdit::UpdateEntryData()
|
||||
@@ -98,8 +137,67 @@ void MacroConditionRecordEdit::UpdateEntryData()
|
||||
return;
|
||||
}
|
||||
|
||||
_recordState->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_recordState));
|
||||
_condition->setCurrentIndex(
|
||||
static_cast<int>(_entryData->GetCondition()));
|
||||
_duration->SetDuration(_entryData->_duration);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionRecordEdit::DurationChanged(const Duration &duration)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_duration = duration;
|
||||
}
|
||||
|
||||
void MacroConditionRecordEdit::SetWidgetVisibility()
|
||||
{
|
||||
_duration->setVisible(_entryData->GetCondition() ==
|
||||
MacroConditionRecord::Condition::DURATION);
|
||||
}
|
||||
|
||||
bool SetupRecordingTimer()
|
||||
{
|
||||
static std::atomic_bool recordingStopped = {true};
|
||||
static std::atomic_bool recordingPaused = {false};
|
||||
static auto handleRecordingEvents = [](enum obs_frontend_event event,
|
||||
void *) {
|
||||
switch (event) {
|
||||
case OBS_FRONTEND_EVENT_RECORDING_STOPPED:
|
||||
recordingStopped = true;
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_RECORDING_STARTED:
|
||||
recordingStopped = false;
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_RECORDING_PAUSED:
|
||||
recordingPaused = true;
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_RECORDING_UNPAUSED:
|
||||
recordingPaused = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
};
|
||||
obs_frontend_add_event_callback(handleRecordingEvents, nullptr);
|
||||
std::thread thread([]() {
|
||||
while (true) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (recordingStopped) {
|
||||
currentRecordingDurationInSeconds = 0;
|
||||
continue;
|
||||
}
|
||||
if (recordingPaused) {
|
||||
continue;
|
||||
}
|
||||
++currentRecordingDurationInSeconds;
|
||||
}
|
||||
});
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
|
||||
namespace advss {
|
||||
|
||||
enum class RecordState {
|
||||
STOP,
|
||||
PAUSE,
|
||||
START,
|
||||
};
|
||||
|
||||
class MacroConditionRecord : public MacroCondition {
|
||||
public:
|
||||
MacroConditionRecord(Macro *m) : MacroCondition(m) {}
|
||||
@@ -24,9 +18,21 @@ public:
|
||||
return std::make_shared<MacroConditionRecord>(m);
|
||||
}
|
||||
|
||||
RecordState _recordState = RecordState::STOP;
|
||||
enum class Condition {
|
||||
STOP,
|
||||
PAUSE,
|
||||
START,
|
||||
DURATION,
|
||||
};
|
||||
|
||||
void SetCondition(Condition);
|
||||
Condition GetCondition() const { return _condition; }
|
||||
Duration _duration;
|
||||
|
||||
private:
|
||||
void SetupTempVars();
|
||||
|
||||
Condition _condition = Condition::STOP;
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
@@ -48,13 +54,15 @@ public:
|
||||
}
|
||||
|
||||
private slots:
|
||||
void StateChanged(int value);
|
||||
|
||||
protected:
|
||||
QComboBox *_recordState;
|
||||
std::shared_ptr<MacroConditionRecord> _entryData;
|
||||
void ConditionChanged(int value);
|
||||
void DurationChanged(const Duration &);
|
||||
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
QComboBox *_condition;
|
||||
DurationSelection *_duration;
|
||||
std::shared_ptr<MacroConditionRecord> _entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-condition-replay-buffer.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -11,35 +10,63 @@ bool MacroConditionReplayBuffer::_registered = MacroConditionFactory::Register(
|
||||
MacroConditionReplayBufferEdit::Create,
|
||||
"AdvSceneSwitcher.condition.replay"});
|
||||
|
||||
const static std::map<ReplayBufferState, std::string> ReplayBufferStates = {
|
||||
{ReplayBufferState::STOP,
|
||||
"AdvSceneSwitcher.condition.replay.state.stopped"},
|
||||
{ReplayBufferState::START,
|
||||
"AdvSceneSwitcher.condition.replay.state.started"},
|
||||
{ReplayBufferState::SAVE,
|
||||
"AdvSceneSwitcher.condition.replay.state.saved"},
|
||||
const static std::map<MacroConditionReplayBuffer::Condition, std::string>
|
||||
conditions = {
|
||||
{MacroConditionReplayBuffer::Condition::STOP,
|
||||
"AdvSceneSwitcher.condition.replay.state.stopped"},
|
||||
{MacroConditionReplayBuffer::Condition::START,
|
||||
"AdvSceneSwitcher.condition.replay.state.started"},
|
||||
{MacroConditionReplayBuffer::Condition::SAVE,
|
||||
"AdvSceneSwitcher.condition.replay.state.saved"},
|
||||
};
|
||||
|
||||
static bool replayBufferSaved = false;
|
||||
|
||||
static std::chrono::high_resolution_clock::time_point replayBufferSaveTime{};
|
||||
static bool setupReplayBufferEventHandler();
|
||||
static bool replayBufferEventHandlerIsSetup = setupReplayBufferEventHandler();
|
||||
|
||||
static bool setupReplayBufferEventHandler()
|
||||
{
|
||||
static auto handleReplayBufferEvent = [](enum obs_frontend_event event,
|
||||
void *) {
|
||||
switch (event) {
|
||||
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED:
|
||||
replayBufferSaveTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
};
|
||||
obs_frontend_add_event_callback(handleReplayBufferEvent, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionReplayBuffer::ReplayBufferWasSaved()
|
||||
{
|
||||
bool timersAreInitialized =
|
||||
_saveTime.time_since_epoch().count() != 0 &&
|
||||
replayBufferSaveTime.time_since_epoch().count() != 0;
|
||||
bool newSaveOccurred = timersAreInitialized &&
|
||||
_saveTime != replayBufferSaveTime;
|
||||
_saveTime = replayBufferSaveTime;
|
||||
return newSaveOccurred;
|
||||
}
|
||||
|
||||
bool MacroConditionReplayBuffer::CheckCondition()
|
||||
{
|
||||
bool stateMatch = false;
|
||||
switch (_state) {
|
||||
case ReplayBufferState::STOP:
|
||||
stateMatch = !obs_frontend_replay_buffer_active();
|
||||
break;
|
||||
case ReplayBufferState::START:
|
||||
stateMatch = obs_frontend_replay_buffer_active();
|
||||
break;
|
||||
case ReplayBufferState::SAVE:
|
||||
if (switcher->replayBufferSaved) {
|
||||
stateMatch = true;
|
||||
switcher->replayBufferSaved = false;
|
||||
}
|
||||
break;
|
||||
case Condition::STOP:
|
||||
return !obs_frontend_replay_buffer_active();
|
||||
case Condition::START:
|
||||
return obs_frontend_replay_buffer_active();
|
||||
case Condition::SAVE:
|
||||
return ReplayBufferWasSaved();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return stateMatch;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroConditionReplayBuffer::Save(obs_data_t *obj) const
|
||||
@@ -52,37 +79,30 @@ bool MacroConditionReplayBuffer::Save(obs_data_t *obj) const
|
||||
bool MacroConditionReplayBuffer::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_state = static_cast<ReplayBufferState>(obs_data_get_int(obj, "state"));
|
||||
_state = static_cast<Condition>(obs_data_get_int(obj, "state"));
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void populateStateSelection(QComboBox *list)
|
||||
{
|
||||
for (auto entry : ReplayBufferStates) {
|
||||
for (const auto &entry : conditions) {
|
||||
list->addItem(obs_module_text(entry.second.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
MacroConditionReplayBufferEdit::MacroConditionReplayBufferEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionReplayBuffer> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent), _state(new QComboBox())
|
||||
{
|
||||
_state = new QComboBox();
|
||||
|
||||
QWidget::connect(_state, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(StateChanged(int)));
|
||||
|
||||
populateStateSelection(_state);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{state}}", _state},
|
||||
};
|
||||
|
||||
auto layout = new QHBoxLayout;
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.condition.replay.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
setLayout(mainLayout);
|
||||
layout, {{"{{state}}", _state}});
|
||||
setLayout(layout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
@@ -96,7 +116,8 @@ void MacroConditionReplayBufferEdit::StateChanged(int value)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_state = static_cast<ReplayBufferState>(value);
|
||||
_entryData->_state =
|
||||
static_cast<MacroConditionReplayBuffer::Condition>(value);
|
||||
}
|
||||
|
||||
void MacroConditionReplayBufferEdit::UpdateEntryData()
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
|
||||
namespace advss {
|
||||
|
||||
enum class ReplayBufferState {
|
||||
STOP,
|
||||
START,
|
||||
SAVE,
|
||||
};
|
||||
|
||||
class MacroConditionReplayBuffer : public MacroCondition {
|
||||
public:
|
||||
MacroConditionReplayBuffer(Macro *m) : MacroCondition(m) {}
|
||||
@@ -24,9 +18,18 @@ public:
|
||||
return std::make_shared<MacroConditionReplayBuffer>(m);
|
||||
}
|
||||
|
||||
ReplayBufferState _state = ReplayBufferState::STOP;
|
||||
enum class Condition {
|
||||
STOP,
|
||||
START,
|
||||
SAVE,
|
||||
};
|
||||
|
||||
Condition _state = Condition::STOP;
|
||||
|
||||
private:
|
||||
bool ReplayBufferWasSaved();
|
||||
|
||||
std::chrono::high_resolution_clock::time_point _saveTime = {};
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QDesktopServices>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -28,17 +27,18 @@ bool MacroConditionRun::CheckCondition()
|
||||
|
||||
bool ret = false;
|
||||
|
||||
switch (_procStatus) {
|
||||
case MacroConditionRun::Status::FAILED_TO_START:
|
||||
switch (_error) {
|
||||
case ProcessConfig::ProcStartError::FAILED_TO_START:
|
||||
SetVariableValue("Failed to start process");
|
||||
ret = false;
|
||||
break;
|
||||
case MacroConditionRun::Status::TIMEOUT:
|
||||
case ProcessConfig::ProcStartError::TIMEOUT:
|
||||
SetVariableValue("Timeout while running process");
|
||||
ret = false;
|
||||
break;
|
||||
case MacroConditionRun::Status::OK:
|
||||
ret = _checkExitCode ? _exitCode == _procExitCode : true;
|
||||
case ProcessConfig::ProcStartError::CRASH:
|
||||
SetVariableValue("Timeout while running process");
|
||||
break;
|
||||
case ProcessConfig::ProcStartError::NONE:
|
||||
ret = _checkExitCode ? _exitCodeToCheck == _procExitCode : true;
|
||||
SetVariableValue(std::to_string(_procExitCode));
|
||||
break;
|
||||
default:
|
||||
@@ -56,42 +56,14 @@ bool MacroConditionRun::CheckCondition()
|
||||
|
||||
void MacroConditionRun::RunProcess()
|
||||
{
|
||||
QProcess process;
|
||||
process.setWorkingDirectory(
|
||||
QString::fromStdString(_procConfig.WorkingDir()));
|
||||
process.start(QString::fromStdString(_procConfig.Path()),
|
||||
_procConfig.Args());
|
||||
int timeout = _timeout.Milliseconds();
|
||||
auto result = _procConfig.StartProcessAndWait(_timeout.Milliseconds());
|
||||
|
||||
vblog(LOG_INFO, "run \"%s\" with a timeout of %d ms",
|
||||
_procConfig.Path().c_str(), timeout);
|
||||
|
||||
bool procFinishedInTime = process.waitForFinished(timeout);
|
||||
|
||||
if (!procFinishedInTime) {
|
||||
if (process.error() == QProcess::FailedToStart) {
|
||||
vblog(LOG_INFO, "failed to start \"%s\"!",
|
||||
_procConfig.Path().c_str());
|
||||
_procStatus = Status::FAILED_TO_START;
|
||||
} else {
|
||||
vblog(LOG_INFO,
|
||||
"timeout while running \"%s\"\nAttempting to kill process!",
|
||||
_procConfig.Path().c_str());
|
||||
process.kill();
|
||||
process.waitForFinished();
|
||||
_procStatus = Status::TIMEOUT;
|
||||
}
|
||||
if (std::holds_alternative<ProcessConfig::ProcStartError>(result)) {
|
||||
_error = std::get<ProcessConfig::ProcStartError>(result);
|
||||
} else {
|
||||
_error = ProcessConfig::ProcStartError::NONE;
|
||||
_procExitCode = std::get<int>(result);
|
||||
}
|
||||
|
||||
bool validExitCode = process.exitStatus() == QProcess::NormalExit;
|
||||
|
||||
if ((_checkExitCode && !validExitCode) || !procFinishedInTime) {
|
||||
_threadDone = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_procExitCode = process.exitCode();
|
||||
_procStatus = Status::OK;
|
||||
_threadDone = true;
|
||||
}
|
||||
|
||||
@@ -100,7 +72,7 @@ bool MacroConditionRun::Save(obs_data_t *obj) const
|
||||
MacroCondition::Save(obj);
|
||||
_procConfig.Save(obj);
|
||||
obs_data_set_bool(obj, "checkExitCode", _checkExitCode);
|
||||
obs_data_set_int(obj, "exitCode", _exitCode);
|
||||
obs_data_set_int(obj, "exitCode", _exitCodeToCheck);
|
||||
_timeout.Save(obj, "timeout");
|
||||
return true;
|
||||
}
|
||||
@@ -110,7 +82,7 @@ bool MacroConditionRun::Load(obs_data_t *obj)
|
||||
MacroCondition::Load(obj);
|
||||
_procConfig.Load(obj);
|
||||
_checkExitCode = obs_data_get_bool(obj, "checkExitCode");
|
||||
_exitCode = obs_data_get_int(obj, "exitCode");
|
||||
_exitCodeToCheck = obs_data_get_int(obj, "exitCode");
|
||||
_timeout.Load(obj, "timeout");
|
||||
return true;
|
||||
}
|
||||
@@ -174,7 +146,7 @@ void MacroConditionRunEdit::UpdateEntryData()
|
||||
_procConfig->SetProcessConfig(_entryData->_procConfig);
|
||||
_timeout->SetDuration(_entryData->_timeout);
|
||||
_checkExitCode->setChecked(_entryData->_checkExitCode);
|
||||
_exitCode->setValue(_entryData->_exitCode);
|
||||
_exitCode->setValue(_entryData->_exitCodeToCheck);
|
||||
}
|
||||
|
||||
void MacroConditionRunEdit::TimeoutChanged(const Duration &dur)
|
||||
@@ -204,7 +176,7 @@ void MacroConditionRunEdit::ExitCodeChanged(int exitCode)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_exitCode = exitCode;
|
||||
_entryData->_exitCodeToCheck = exitCode;
|
||||
}
|
||||
|
||||
void MacroConditionRunEdit::ProcessConfigChanged(const ProcessConfig &conf)
|
||||
|
||||
@@ -25,22 +25,15 @@ public:
|
||||
|
||||
ProcessConfig _procConfig;
|
||||
bool _checkExitCode = true;
|
||||
int _exitCode = 0;
|
||||
int _exitCodeToCheck = 0;
|
||||
Duration _timeout = Duration(0.1);
|
||||
|
||||
private:
|
||||
enum class Status {
|
||||
NONE,
|
||||
FAILED_TO_START,
|
||||
TIMEOUT,
|
||||
OK,
|
||||
};
|
||||
|
||||
void RunProcess();
|
||||
|
||||
std::thread _thread;
|
||||
std::atomic_bool _threadDone{true};
|
||||
Status _procStatus = Status::NONE;
|
||||
ProcessConfig::ProcStartError _error =
|
||||
ProcessConfig::ProcStartError::NONE;
|
||||
int _procExitCode = 0;
|
||||
|
||||
static bool _registered;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "macro-condition-scene.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "scene-switch-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -53,23 +53,22 @@ static OBSWeakSource getCurrentSceneHelper(bool useTransitionTargetScene)
|
||||
obs_source_release(current);
|
||||
return weak;
|
||||
}
|
||||
return switcher->currentScene;
|
||||
return GetCurrentScene();
|
||||
}
|
||||
|
||||
static OBSWeakSource getPreviousSceneHelper(bool useTransitionTargetScene)
|
||||
{
|
||||
if (switcher->AnySceneTransitionStarted() && useTransitionTargetScene) {
|
||||
return switcher->currentScene;
|
||||
if (AnySceneTransitionStarted() && useTransitionTargetScene) {
|
||||
return GetCurrentScene();
|
||||
}
|
||||
return switcher->previousScene;
|
||||
return GetPreviousScene();
|
||||
}
|
||||
|
||||
bool MacroConditionScene::CheckCondition()
|
||||
{
|
||||
bool sceneChanged = _lastSceneChangeTime !=
|
||||
switcher->lastSceneChangeTime;
|
||||
bool sceneChanged = _lastSceneChangeTime != GetLastSceneChangeTime();
|
||||
if (sceneChanged) {
|
||||
_lastSceneChangeTime = switcher->lastSceneChangeTime;
|
||||
_lastSceneChangeTime = GetLastSceneChangeTime();
|
||||
}
|
||||
|
||||
switch (_type) {
|
||||
@@ -95,14 +94,14 @@ bool MacroConditionScene::CheckCondition()
|
||||
return scene == _scene.GetScene(false);
|
||||
}
|
||||
case Type::CHANGED:
|
||||
SetVariableValue(GetWeakSourceName(switcher->currentScene));
|
||||
SetVariableValue(GetWeakSourceName(GetCurrentScene()));
|
||||
SetTempVarValue("current",
|
||||
GetWeakSourceName(switcher->currentScene));
|
||||
GetWeakSourceName(GetCurrentScene()));
|
||||
return sceneChanged;
|
||||
case Type::NOT_CHANGED:
|
||||
SetVariableValue(GetWeakSourceName(switcher->currentScene));
|
||||
SetVariableValue(GetWeakSourceName(GetCurrentScene()));
|
||||
SetTempVarValue("current",
|
||||
GetWeakSourceName(switcher->currentScene));
|
||||
GetWeakSourceName(GetCurrentScene()));
|
||||
return !sceneChanged;
|
||||
case Type::CURRENT_PATTERN: {
|
||||
auto scene = getCurrentSceneHelper(_useTransitionTargetScene);
|
||||
@@ -189,8 +188,8 @@ bool MacroConditionScene::Load(obs_data_t *obj)
|
||||
break;
|
||||
default:
|
||||
blog(LOG_WARNING,
|
||||
"failed to convert scene condition type (%d) for macro %s",
|
||||
oldType, GetMacro()->Name().c_str());
|
||||
"failed to convert scene condition type (%d)",
|
||||
oldType);
|
||||
_type = Type::CURRENT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-condition-streaming.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -25,6 +24,32 @@ const static std::map<MacroConditionStream::Condition, std::string>
|
||||
"AdvSceneSwitcher.condition.stream.state.keyFrameInterval"},
|
||||
};
|
||||
|
||||
static bool setupStreamingEventHandler();
|
||||
static bool steamingEventHandlerIsSetup = setupStreamingEventHandler();
|
||||
static std::chrono::high_resolution_clock::time_point streamStartTime{};
|
||||
static std::chrono::high_resolution_clock::time_point streamStopTime{};
|
||||
|
||||
bool setupStreamingEventHandler()
|
||||
{
|
||||
static auto handleStreamingEvents = [](enum obs_frontend_event event,
|
||||
void *) {
|
||||
switch (event) {
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STARTING:
|
||||
streamStartTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STOPPING:
|
||||
streamStopTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
};
|
||||
obs_frontend_add_event_callback(handleStreamingEvents, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
int MacroConditionStream::GetKeyFrameInterval()
|
||||
{
|
||||
const auto configPath = GetPathInProfileDir("streamEncoder.json");
|
||||
@@ -42,10 +67,8 @@ bool MacroConditionStream::CheckCondition()
|
||||
{
|
||||
bool match = false;
|
||||
|
||||
bool streamStarting = switcher->lastStreamStartingTime !=
|
||||
_lastStreamStartingTime;
|
||||
bool streamStopping = switcher->lastStreamStoppingTime !=
|
||||
_lastStreamStoppingTime;
|
||||
bool streamStarting = streamStartTime != _lastStreamStartingTime;
|
||||
bool streamStopping = streamStopTime != _lastStreamStoppingTime;
|
||||
|
||||
switch (_condition) {
|
||||
case Condition::STOP:
|
||||
@@ -68,10 +91,10 @@ bool MacroConditionStream::CheckCondition()
|
||||
}
|
||||
|
||||
if (streamStarting) {
|
||||
_lastStreamStartingTime = switcher->lastStreamStartingTime;
|
||||
_lastStreamStartingTime = streamStartTime;
|
||||
}
|
||||
if (streamStopping) {
|
||||
_lastStreamStoppingTime = switcher->lastStreamStoppingTime;
|
||||
_lastStreamStoppingTime = streamStopTime;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "macro-condition-transition.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "scene-switch-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
@@ -50,8 +50,8 @@ static bool isTargetScene(OBSWeakSource &target)
|
||||
bool MacroConditionTransition::CheckCondition()
|
||||
{
|
||||
bool anyTransitionEnded = _lastTransitionEndTime !=
|
||||
switcher->lastTransitionEndTime;
|
||||
bool anyTransitionStarted = switcher->AnySceneTransitionStarted();
|
||||
GetLastTransitionEndTime();
|
||||
bool anyTransitionStarted = AnySceneTransitionStarted();
|
||||
bool transitionStarted = false;
|
||||
bool transitionEnded = false;
|
||||
|
||||
@@ -82,7 +82,7 @@ bool MacroConditionTransition::CheckCondition()
|
||||
break;
|
||||
case TransitionCondition::TRANSITION_SOURCE:
|
||||
ret = anyTransitionStarted &&
|
||||
_scene.GetScene() == switcher->currentScene;
|
||||
_scene.GetScene() == GetCurrentScene();
|
||||
break;
|
||||
case TransitionCondition::TRANSITION_TARGET: {
|
||||
auto scene = _scene.GetScene();
|
||||
@@ -101,7 +101,7 @@ bool MacroConditionTransition::CheckCondition()
|
||||
_ended = false;
|
||||
}
|
||||
if (anyTransitionEnded) {
|
||||
_lastTransitionEndTime = switcher->lastTransitionEndTime;
|
||||
_lastTransitionEndTime = GetLastTransitionEndTime();
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "macro-condition-websocket.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <regex>
|
||||
@@ -34,28 +33,24 @@ static bool matchRegex(const RegexConfig &conf, const std::string &msg,
|
||||
|
||||
bool MacroConditionWebsocket::CheckCondition()
|
||||
{
|
||||
const std::vector<std::string> *messages = nullptr;
|
||||
std::vector<std::string> messages;
|
||||
switch (_type) {
|
||||
case MacroConditionWebsocket::Type::REQUEST:
|
||||
messages = &switcher->websocketMessages;
|
||||
messages = GetWebsocketMessages();
|
||||
break;
|
||||
case MacroConditionWebsocket::Type::EVENT: {
|
||||
auto connection = _connection.lock();
|
||||
if (!connection) {
|
||||
return false;
|
||||
}
|
||||
messages = &connection->Events();
|
||||
messages = connection->Events();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!messages) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &msg : *messages) {
|
||||
for (const auto &msg : messages) {
|
||||
if (_regex.Enabled()) {
|
||||
if (matchRegex(_regex, msg, _message)) {
|
||||
SetVariableValue(msg);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "macro-condition-window.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "platform-funcs.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -43,7 +43,8 @@ static bool windowContainsText(const std::string &window,
|
||||
bool MacroConditionWindow::WindowMatchesRequirements(
|
||||
const std::string &window) const
|
||||
{
|
||||
const bool focusCheckOK = (!_focus || window == switcher->currentTitle);
|
||||
const bool focusCheckOK =
|
||||
(!_focus || window == ForegroundWindowTitle());
|
||||
if (!focusCheckOK) {
|
||||
return false;
|
||||
}
|
||||
@@ -104,13 +105,13 @@ void MacroConditionWindow::SetVariableValueBasedOnMatch(
|
||||
auto text = GetTextInWindow(matchWindow);
|
||||
SetVariableValue(text.value_or(""));
|
||||
} else {
|
||||
SetVariableValue(switcher->currentTitle);
|
||||
SetVariableValue(ForegroundWindowTitle());
|
||||
}
|
||||
}
|
||||
|
||||
static bool foregroundWindowChanged()
|
||||
{
|
||||
return switcher->currentTitle != switcher->lastTitle;
|
||||
return ForegroundWindowTitle() != PreviousForegroundWindowTitle();
|
||||
}
|
||||
|
||||
bool MacroConditionWindow::CheckCondition()
|
||||
@@ -176,6 +177,7 @@ std::string MacroConditionWindow::GetShortDesc() const
|
||||
|
||||
void MacroConditionWindow::SetupTempVars()
|
||||
{
|
||||
MacroCondition::SetupTempVars();
|
||||
AddTempvar(
|
||||
"window",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.window.window"),
|
||||
@@ -431,7 +433,7 @@ void MacroConditionWindowEdit::WindowFocusChanged(int state)
|
||||
|
||||
void MacroConditionWindowEdit::UpdateFocusWindow()
|
||||
{
|
||||
_focusWindow->setText(QString::fromStdString(switcher->currentTitle));
|
||||
_focusWindow->setText(QString::fromStdString(ForegroundWindowTitle()));
|
||||
}
|
||||
|
||||
void MacroConditionWindowEdit::SetWidgetVisibility()
|
||||
|
||||
59
src/macro-core/macro-helpers.cpp
Normal file
59
src/macro-core/macro-helpers.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "macro-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
static std::atomic_bool abortMacroWait = {false};
|
||||
static std::atomic_bool macroSceneSwitched = {false};
|
||||
static std::atomic_int shutdownConditionCount = {0};
|
||||
|
||||
std::condition_variable &GetMacroWaitCV()
|
||||
{
|
||||
static std::condition_variable cv;
|
||||
return cv;
|
||||
}
|
||||
|
||||
std::condition_variable &GetMacroTransitionCV()
|
||||
{
|
||||
static std::condition_variable cv;
|
||||
return cv;
|
||||
}
|
||||
|
||||
std::atomic_bool &MacroWaitShouldAbort()
|
||||
{
|
||||
return abortMacroWait;
|
||||
}
|
||||
|
||||
void SetMacroAbortWait(bool value)
|
||||
{
|
||||
abortMacroWait = value;
|
||||
}
|
||||
|
||||
bool ShutdownCheckIsNecessary()
|
||||
{
|
||||
return shutdownConditionCount > 0;
|
||||
}
|
||||
|
||||
std::atomic_int &GetShutdownConditionCount()
|
||||
{
|
||||
return shutdownConditionCount;
|
||||
}
|
||||
|
||||
void SetMacroSwitchedScene(bool value)
|
||||
{
|
||||
static bool setupDone = false;
|
||||
if (!setupDone) {
|
||||
// Will always be called with switcher lock already held
|
||||
AddIntervalResetStep([]() { macroSceneSwitched = false; },
|
||||
false);
|
||||
setupDone = true;
|
||||
}
|
||||
macroSceneSwitched = value;
|
||||
}
|
||||
|
||||
bool MacroSwitchedScene()
|
||||
{
|
||||
return macroSceneSwitched;
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
21
src/macro-core/macro-helpers.hpp
Normal file
21
src/macro-core/macro-helpers.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <string_view>
|
||||
|
||||
namespace advss {
|
||||
|
||||
constexpr std::string_view GetSceneSwitchActionId()
|
||||
{
|
||||
return "scene_switch";
|
||||
}
|
||||
std::condition_variable &GetMacroWaitCV();
|
||||
std::condition_variable &GetMacroTransitionCV();
|
||||
std::atomic_bool &MacroWaitShouldAbort();
|
||||
void SetMacroAbortWait(bool);
|
||||
bool ShutdownCheckIsNecessary();
|
||||
std::atomic_int &GetShutdownConditionCount();
|
||||
void SetMacroSwitchedScene(bool value);
|
||||
bool MacroSwitchedScene();
|
||||
|
||||
} // namespace advss
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace advss {
|
||||
|
||||
static MacroProperties macroProperties;
|
||||
|
||||
void MacroProperties::Save(obs_data_t *obj) const
|
||||
{
|
||||
auto data = obs_data_create();
|
||||
@@ -325,4 +327,19 @@ bool MacroPropertiesDialog::AskForSettings(QWidget *parent,
|
||||
return true;
|
||||
}
|
||||
|
||||
MacroProperties &GetGlobalMacroProperties()
|
||||
{
|
||||
return macroProperties;
|
||||
}
|
||||
|
||||
void SaveGlobalMacroProperties(obs_data_t *obj)
|
||||
{
|
||||
macroProperties.Save(obj);
|
||||
}
|
||||
|
||||
void LoadGlobalMacroProperties(obs_data_t *obj)
|
||||
{
|
||||
macroProperties.Load(obj);
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -68,4 +68,8 @@ private:
|
||||
int _conditionsFalseTextRow = -1;
|
||||
};
|
||||
|
||||
MacroProperties &GetGlobalMacroProperties();
|
||||
void SaveGlobalMacroProperties(obs_data_t *obj);
|
||||
void LoadGlobalMacroProperties(obs_data_t *obj);
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -44,8 +44,28 @@ MacroSegmentList::~MacroSegmentList()
|
||||
}
|
||||
}
|
||||
|
||||
static bool posIsInScrollbar(const QScrollBar *scrollbar, const QPoint &pos)
|
||||
{
|
||||
if (!scrollbar) {
|
||||
return false;
|
||||
}
|
||||
if (!scrollbar->isVisible()) {
|
||||
return false;
|
||||
}
|
||||
const auto geo = scrollbar->geometry();
|
||||
const auto globalGeo = QRect(scrollbar->mapToGlobal(geo.topLeft()),
|
||||
scrollbar->mapToGlobal(geo.bottomRight()));
|
||||
return globalGeo.contains(pos);
|
||||
}
|
||||
|
||||
int MacroSegmentList::GetDragIndex(const QPoint &pos)
|
||||
{
|
||||
// Don't drag widget when interacting with the scrollbars
|
||||
if (posIsInScrollbar(horizontalScrollBar(), mapTo(this, pos)) ||
|
||||
posIsInScrollbar(verticalScrollBar(), mapTo(this, pos))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < _contentLayout->count(); ++idx) {
|
||||
auto item = _contentLayout->itemAt(idx);
|
||||
if (!item) {
|
||||
@@ -161,7 +181,7 @@ void MacroSegmentList::mousePressEvent(QMouseEvent *event)
|
||||
#else
|
||||
_dragPosition = GetDragIndex(event->globalPosition().toPoint());
|
||||
#endif
|
||||
emit SelectionChagned(_dragPosition);
|
||||
emit SelectionChanged(_dragPosition);
|
||||
} else {
|
||||
_dragPosition = -1;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
QVBoxLayout *ContentLayout() { return _contentLayout; }
|
||||
|
||||
signals:
|
||||
void SelectionChagned(int idx);
|
||||
void SelectionChanged(int idx);
|
||||
void Reorder(int source, int target);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -146,7 +146,6 @@ void MacroSegment::InvalidateTempVarValues()
|
||||
std::optional<const TempVariable>
|
||||
MacroSegment::GetTempVar(const std::string &id) const
|
||||
{
|
||||
TempVariable *result = nullptr;
|
||||
for (auto &var : _tempVariables) {
|
||||
if (var.ID() == id) {
|
||||
return var;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// so it makes sense to include them here:
|
||||
#include "log-helper.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "sync-helper.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
#include "temp-variable.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "macro-selection.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
@@ -12,7 +12,7 @@ MacroSelection::MacroSelection(QWidget *parent)
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectMacro"))
|
||||
{
|
||||
for (const auto &m : switcher->macros) {
|
||||
for (const auto &m : GetMacros()) {
|
||||
if (m->IsGroup()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ bool AdvSceneSwitcher::AddNewMacro(std::shared_ptr<Macro> &res,
|
||||
}
|
||||
|
||||
res = std::make_shared<Macro>(
|
||||
name, switcher->macroProperties._newMacroRegisterHotkeys);
|
||||
name, GetGlobalMacroProperties()._newMacroRegisterHotkeys);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> ¯os,
|
||||
subitems.reserve(group->GroupSize());
|
||||
|
||||
// Find all subitems
|
||||
for (auto it = switcher->macros.begin(); it < switcher->macros.end();
|
||||
it++) {
|
||||
auto allMacros = GetMacros();
|
||||
for (auto it = allMacros.begin(); it < allMacros.end(); it++) {
|
||||
if ((*it)->Name() == group->Name()) {
|
||||
for (uint32_t i = 1; i <= group->GroupSize(); i++) {
|
||||
subitems.emplace_back(*std::next(it, i));
|
||||
@@ -235,21 +235,18 @@ void AdvSceneSwitcher::ExportMacros()
|
||||
}
|
||||
}
|
||||
|
||||
auto data = obs_data_create();
|
||||
auto macroArray = obs_data_array_create();
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
OBSDataArrayAutoRelease macroArray = obs_data_array_create();
|
||||
for (const auto ¯o : macros) {
|
||||
obs_data_t *obj = obs_data_create();
|
||||
OBSDataAutoRelease obj = obs_data_create();
|
||||
macro->Save(obj);
|
||||
obs_data_array_push_back(macroArray, obj);
|
||||
obs_data_release(obj);
|
||||
}
|
||||
obs_data_set_array(data, "macros", macroArray);
|
||||
switcher->SaveVariables(data);
|
||||
obs_data_array_release(macroArray);
|
||||
SaveVariables(data);
|
||||
obs_data_set_string(data, "version", g_GIT_TAG);
|
||||
auto json = obs_data_get_json(data);
|
||||
QString exportString(json);
|
||||
obs_data_release(data);
|
||||
|
||||
MacroExportImportDialog::ExportMacros(exportString);
|
||||
}
|
||||
@@ -268,8 +265,9 @@ void AdvSceneSwitcher::SetupMacroSegmentSelection(MacroSection type, int idx)
|
||||
return;
|
||||
}
|
||||
|
||||
MacroSegmentList *setList, *resetList1, *resetList2;
|
||||
int *setIdx, *resetIdx1, *resetIdx2;
|
||||
MacroSegmentList *setList = nullptr, *resetList1 = nullptr,
|
||||
*resetList2 = nullptr;
|
||||
int *setIdx = nullptr, *resetIdx1 = nullptr, *resetIdx2 = nullptr;
|
||||
std::deque<std::shared_ptr<MacroSegment>> segements;
|
||||
|
||||
switch (type) {
|
||||
@@ -384,7 +382,7 @@ static void importVariables(obs_data_t *obj)
|
||||
if (variableWithNameExists(var->Name())) {
|
||||
continue;
|
||||
}
|
||||
switcher->variables.emplace_back(var);
|
||||
GetVariables().emplace_back(var);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +392,8 @@ void AdvSceneSwitcher::ImportMacros()
|
||||
if (!MacroExportImportDialog::ImportMacros(json)) {
|
||||
return;
|
||||
}
|
||||
auto data = obs_data_create_from_json(json.toStdString().c_str());
|
||||
OBSDataAutoRelease data =
|
||||
obs_data_create_from_json(json.toStdString().c_str());
|
||||
if (!data) {
|
||||
DisplayMessage(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.import.invalid"));
|
||||
@@ -410,28 +409,27 @@ void AdvSceneSwitcher::ImportMacros()
|
||||
version);
|
||||
}
|
||||
|
||||
auto array = obs_data_get_array(data, "macros");
|
||||
OBSDataArrayAutoRelease array = obs_data_get_array(data, "macros");
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
int groupSize = 0;
|
||||
std::shared_ptr<Macro> group;
|
||||
std::vector<std::shared_ptr<Macro>> importedMacros;
|
||||
|
||||
auto lock = LockContext();
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
obs_data_t *array_obj = obs_data_array_item(array, i);
|
||||
OBSDataAutoRelease array_obj = obs_data_array_item(array, i);
|
||||
auto macro = std::make_shared<Macro>();
|
||||
macro->Load(array_obj);
|
||||
macro->PostLoad();
|
||||
|
||||
if (macroNameExists(macro->Name()) &&
|
||||
!ResolveMacroImportNameConflict(macro)) {
|
||||
obs_data_release(array_obj);
|
||||
groupSize--;
|
||||
continue;
|
||||
}
|
||||
|
||||
switcher->macros.emplace_back(macro);
|
||||
importedMacros.emplace_back(macro);
|
||||
GetMacros().emplace_back(macro);
|
||||
if (groupSize > 0 && !macro->IsGroup()) {
|
||||
Macro::PrepareMoveToGroup(group, macro);
|
||||
groupSize--;
|
||||
@@ -445,14 +443,14 @@ void AdvSceneSwitcher::ImportMacros()
|
||||
// to the group as they come up.
|
||||
macro->ResetGroupSize();
|
||||
}
|
||||
|
||||
obs_data_release(array_obj);
|
||||
}
|
||||
obs_data_array_release(array);
|
||||
obs_data_release(data);
|
||||
|
||||
ui->macros->Reset(switcher->macros,
|
||||
switcher->macroProperties._highlightExecuted);
|
||||
for (const auto ¯o : importedMacros) {
|
||||
macro->PostLoad();
|
||||
}
|
||||
|
||||
ui->macros->Reset(GetMacros(),
|
||||
GetGlobalMacroProperties()._highlightExecuted);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroName_editingFinished()
|
||||
@@ -700,8 +698,7 @@ void AdvSceneSwitcher::MacroSelectionAboutToChange()
|
||||
// actions nor elseActions being visible when the condition <-> action
|
||||
// splitter is moved
|
||||
if (elsePos[0] == 0 && elsePos[1] == 0) {
|
||||
macro->SetElseActionSplitterPosition(QList<int>()
|
||||
<< 999999 << 0);
|
||||
maximizeFirstSplitterEntry(ui->macroElseActionSplitter);
|
||||
return;
|
||||
}
|
||||
macro->SetElseActionSplitterPosition(
|
||||
@@ -732,8 +729,8 @@ void AdvSceneSwitcher::MacroSelectionChanged()
|
||||
|
||||
void AdvSceneSwitcher::HighlightOnChange()
|
||||
{
|
||||
if (!switcher->macroProperties._highlightActions &&
|
||||
!switcher->macroProperties._highlightExecuted) {
|
||||
if (!GetGlobalMacroProperties()._highlightActions &&
|
||||
!GetGlobalMacroProperties()._highlightExecuted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -750,13 +747,13 @@ void AdvSceneSwitcher::HighlightOnChange()
|
||||
|
||||
void AdvSceneSwitcher::on_macroProperties_clicked()
|
||||
{
|
||||
MacroProperties prop = switcher->macroProperties;
|
||||
MacroProperties prop = GetGlobalMacroProperties();
|
||||
bool accepted = MacroPropertiesDialog::AskForSettings(
|
||||
this, prop, GetSelectedMacro().get());
|
||||
if (!accepted) {
|
||||
return;
|
||||
}
|
||||
switcher->macroProperties = prop;
|
||||
GetGlobalMacroProperties() = prop;
|
||||
emit HighlightMacrosChanged(prop._highlightExecuted);
|
||||
emit HighlightActionsChanged(prop._highlightActions);
|
||||
emit HighlightConditionsChanged(prop._highlightConditions);
|
||||
@@ -790,11 +787,13 @@ bool shouldRestoreSplitter(const QList<int> &pos)
|
||||
|
||||
void AdvSceneSwitcher::SetupMacroTab()
|
||||
{
|
||||
if (switcher->macros.size() == 0 && !switcher->disableHints) {
|
||||
ui->macroElseActions->installEventFilter(this);
|
||||
|
||||
if (GetMacros().size() == 0 && !switcher->disableHints) {
|
||||
addPulse = PulseWidget(ui->macroAdd, QColor(Qt::green));
|
||||
}
|
||||
ui->macros->Reset(switcher->macros,
|
||||
switcher->macroProperties._highlightExecuted);
|
||||
ui->macros->Reset(GetMacros(),
|
||||
GetGlobalMacroProperties()._highlightExecuted);
|
||||
connect(ui->macros, SIGNAL(MacroSelectionAboutToChange()), this,
|
||||
SLOT(MacroSelectionAboutToChange()));
|
||||
connect(ui->macros, SIGNAL(MacroSelectionChanged()), this,
|
||||
@@ -803,21 +802,21 @@ void AdvSceneSwitcher::SetupMacroTab()
|
||||
|
||||
ui->conditionsList->SetHelpMsg(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.editConditionHelp"));
|
||||
connect(ui->conditionsList, &MacroSegmentList::SelectionChagned, this,
|
||||
connect(ui->conditionsList, &MacroSegmentList::SelectionChanged, this,
|
||||
&AdvSceneSwitcher::MacroConditionSelectionChanged);
|
||||
connect(ui->conditionsList, &MacroSegmentList::Reorder, this,
|
||||
&AdvSceneSwitcher::MacroConditionReorder);
|
||||
|
||||
ui->actionsList->SetHelpMsg(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.editActionHelp"));
|
||||
connect(ui->actionsList, &MacroSegmentList::SelectionChagned, this,
|
||||
connect(ui->actionsList, &MacroSegmentList::SelectionChanged, this,
|
||||
&AdvSceneSwitcher::MacroActionSelectionChanged);
|
||||
connect(ui->actionsList, &MacroSegmentList::Reorder, this,
|
||||
&AdvSceneSwitcher::MacroActionReorder);
|
||||
|
||||
ui->elseActionsList->SetHelpMsg(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.editElseActionHelp"));
|
||||
connect(ui->elseActionsList, &MacroSegmentList::SelectionChagned, this,
|
||||
connect(ui->elseActionsList, &MacroSegmentList::SelectionChanged, this,
|
||||
&AdvSceneSwitcher::MacroElseActionSelectionChanged);
|
||||
connect(ui->elseActionsList, &MacroSegmentList::Reorder, this,
|
||||
&AdvSceneSwitcher::MacroElseActionReorder);
|
||||
@@ -862,6 +861,8 @@ void AdvSceneSwitcher::SetupMacroTab()
|
||||
SetButtonIcon(ui->conditionTop, (pathPrefix + "DoubleUp.svg").c_str());
|
||||
SetButtonIcon(ui->conditionBottom,
|
||||
(pathPrefix + "DoubleDown.svg").c_str());
|
||||
SetButtonIcon(ui->toggleElseActions,
|
||||
(pathPrefix + "NotEqual.svg").c_str());
|
||||
|
||||
// Reserve more space for macro edit area than for the macro list
|
||||
ui->macroListMacroEditSplitter->setStretchFactor(0, 1);
|
||||
@@ -988,13 +989,12 @@ void AdvSceneSwitcher::CopyMacro()
|
||||
return;
|
||||
}
|
||||
|
||||
obs_data_t *data = obs_data_create();
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
macro->Save(data);
|
||||
newMacro->Load(data);
|
||||
newMacro->PostLoad();
|
||||
newMacro->SetName(name);
|
||||
Macro::PrepareMoveToGroup(macro->Parent(), newMacro);
|
||||
obs_data_release(data);
|
||||
|
||||
ui->macros->Add(newMacro, macro);
|
||||
ui->macroAdd->disconnect(addPulse);
|
||||
@@ -1100,6 +1100,31 @@ void AdvSceneSwitcher::MaximizeConditions()
|
||||
MinimizeActions();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_toggleElseActions_clicked()
|
||||
{
|
||||
auto elsePosition = ui->macroElseActionSplitter->sizes();
|
||||
if (elsePosition[1] == 0) {
|
||||
centerSplitterPosition(ui->macroElseActionSplitter);
|
||||
return;
|
||||
}
|
||||
|
||||
maximizeFirstSplitterEntry(ui->macroElseActionSplitter);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::SetElseActionsStateToHidden()
|
||||
{
|
||||
ui->toggleElseActions->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.toggleElseActions.show.tooltip"));
|
||||
ui->toggleElseActions->setChecked(false);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::SetElseActionsStateToVisible()
|
||||
{
|
||||
ui->toggleElseActions->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.toggleElseActions.hide.tooltip"));
|
||||
ui->toggleElseActions->setChecked(true);
|
||||
}
|
||||
|
||||
bool AdvSceneSwitcher::MacroTabIsInFocus()
|
||||
{
|
||||
return isActiveWindow() && isAncestorOf(focusWidget()) &&
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "macro-tree.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
|
||||
#include <obs.h>
|
||||
#include <string>
|
||||
@@ -395,7 +395,7 @@ CountItemsVisibleInModel(const std::deque<std::shared_ptr<Macro>> ¯os)
|
||||
|
||||
void MacroTreeModel::Add(std::shared_ptr<Macro> item)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto idx = CountItemsVisibleInModel(_macros);
|
||||
beginInsertRows(QModelIndex(), idx, idx);
|
||||
_macros.emplace_back(item);
|
||||
@@ -408,7 +408,7 @@ void MacroTreeModel::Add(std::shared_ptr<Macro> item)
|
||||
|
||||
void MacroTreeModel::Remove(std::shared_ptr<Macro> item)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto uiStartIdx = GetItemModelIndex(item);
|
||||
if (uiStartIdx == -1) {
|
||||
return;
|
||||
@@ -643,7 +643,7 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
QString name = GetNewGroupName();
|
||||
std::vector<std::shared_ptr<Macro>> itemsToGroup;
|
||||
itemsToGroup.reserve(indices.size());
|
||||
@@ -691,7 +691,7 @@ void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
for (int i = indices.count() - 1; i >= 0; i--) {
|
||||
std::shared_ptr<Macro> item = _macros[ModelIndexToMacroIndex(
|
||||
indices[i].row(), _macros)];
|
||||
@@ -1055,7 +1055,7 @@ void MacroTree::dropEvent(QDropEvent *event)
|
||||
}
|
||||
|
||||
// Move items in backend
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
int to = row;
|
||||
try {
|
||||
to = ModelIndexToMacroIndex(row, items);
|
||||
@@ -1181,7 +1181,7 @@ void MacroTree::Remove(std::shared_ptr<Macro> item) const
|
||||
|
||||
void MacroTree::Up(std::shared_ptr<Macro> item) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto above = GetModel()->Neighbor(item, true);
|
||||
if (!above) {
|
||||
return;
|
||||
@@ -1207,7 +1207,7 @@ void MacroTree::Up(std::shared_ptr<Macro> item) const
|
||||
|
||||
void MacroTree::Down(std::shared_ptr<Macro> item) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto lock = LockContext();
|
||||
auto below = GetModel()->Neighbor(item, false);
|
||||
if (!below) {
|
||||
return;
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
#include "macro.hpp"
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "macro-action-factory.hpp"
|
||||
#include "macro-condition-factory.hpp"
|
||||
#include "macro-dock.hpp"
|
||||
#include "macro-action-scene-switch.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "hotkey.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <limits>
|
||||
#undef max
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace advss {
|
||||
|
||||
constexpr int perfLogThreshold = 300;
|
||||
static constexpr int perfLogThreshold = 300;
|
||||
static std::deque<std::shared_ptr<Macro>> macros;
|
||||
|
||||
Macro::Macro(const std::string &name, const bool addHotkey)
|
||||
{
|
||||
@@ -33,7 +37,7 @@ Macro::~Macro()
|
||||
|
||||
// Keep the dock widgets in case of shutdown so they can be restored by
|
||||
// OBS on startup
|
||||
if (!switcher->obsIsShuttingDown) {
|
||||
if (!OBSIsShuttingDown()) {
|
||||
RemoveDock();
|
||||
}
|
||||
}
|
||||
@@ -53,9 +57,8 @@ Macro::CreateGroup(const std::string &name,
|
||||
|
||||
void Macro::RemoveGroup(std::shared_ptr<Macro> group)
|
||||
{
|
||||
auto it = std::find(switcher->macros.begin(), switcher->macros.end(),
|
||||
group);
|
||||
if (it == switcher->macros.end()) {
|
||||
auto it = std::find(macros.begin(), macros.end(), group);
|
||||
if (it == macros.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,12 +68,12 @@ void Macro::RemoveGroup(std::shared_ptr<Macro> group)
|
||||
(*m)->SetParent(nullptr);
|
||||
}
|
||||
|
||||
switcher->macros.erase(it);
|
||||
macros.erase(it);
|
||||
}
|
||||
|
||||
void Macro::PrepareMoveToGroup(Macro *group, std::shared_ptr<Macro> item)
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
for (const auto &m : macros) {
|
||||
if (m.get() == group) {
|
||||
PrepareMoveToGroup(m, item);
|
||||
return;
|
||||
@@ -149,6 +152,7 @@ bool Macro::CeckMatch()
|
||||
}
|
||||
break;
|
||||
case LogicType::OR_NOT:
|
||||
_matched = _matched || !cond;
|
||||
if (!cond) {
|
||||
c->SetHighlight();
|
||||
}
|
||||
@@ -350,7 +354,7 @@ void Macro::AddHelperThread(std::thread &&newThread)
|
||||
void Macro::Stop()
|
||||
{
|
||||
_stop = true;
|
||||
switcher->macroWaitCv.notify_all();
|
||||
GetMacroWaitCV().notify_all();
|
||||
for (auto &t : _helperThreads) {
|
||||
if (t.joinable()) {
|
||||
t.join();
|
||||
@@ -742,15 +746,13 @@ bool Macro::PostLoad()
|
||||
|
||||
bool Macro::SwitchesScene() const
|
||||
{
|
||||
MacroActionSwitchScene temp(nullptr);
|
||||
auto sceneSwitchId = temp.GetId();
|
||||
for (const auto &a : _actions) {
|
||||
if (a->GetId() == sceneSwitchId) {
|
||||
if (a->GetId() == GetSceneSwitchActionId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (const auto &a : _elseActions) {
|
||||
if (a->GetId() == sceneSwitchId) {
|
||||
if (a->GetId() == GetSceneSwitchActionId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -946,7 +948,7 @@ void Macro::EnableDock(bool value)
|
||||
// geometry set here.
|
||||
// The function calls here are only intended to attempt to restore the
|
||||
// dock status when switching scene collections.
|
||||
if (switcher->startupLoadDone) {
|
||||
if (InitialLoadIsComplete()) {
|
||||
_dock->setVisible(_dockIsVisible);
|
||||
if (window->dockWidgetArea(_dock) != _dockArea) {
|
||||
window->addDockWidget(_dockArea, _dock);
|
||||
@@ -1162,12 +1164,10 @@ void Macro::SetHotkeysDesc() const
|
||||
_name, _togglePauseHotkey);
|
||||
}
|
||||
|
||||
void SwitcherData::SaveMacros(obs_data_t *obj)
|
||||
void SaveMacros(obs_data_t *obj)
|
||||
{
|
||||
switcher->macroProperties.Save(obj);
|
||||
|
||||
obs_data_array_t *macroArray = obs_data_array_create();
|
||||
for (auto &m : macros) {
|
||||
for (const auto &m : macros) {
|
||||
obs_data_t *array_obj = obs_data_create();
|
||||
|
||||
m->Save(array_obj);
|
||||
@@ -1179,10 +1179,9 @@ void SwitcherData::SaveMacros(obs_data_t *obj)
|
||||
obs_data_array_release(macroArray);
|
||||
}
|
||||
|
||||
void SwitcherData::LoadMacros(obs_data_t *obj)
|
||||
void LoadMacros(obs_data_t *obj)
|
||||
{
|
||||
Hotkey::ClearAllHotkeys();
|
||||
switcher->macroProperties.Load(obj);
|
||||
|
||||
macros.clear();
|
||||
obs_data_array_t *macroArray = obs_data_get_array(obj, "macros");
|
||||
@@ -1199,7 +1198,7 @@ void SwitcherData::LoadMacros(obs_data_t *obj)
|
||||
int groupCount = 0;
|
||||
std::shared_ptr<Macro> group;
|
||||
std::vector<std::shared_ptr<Macro>> invalidGroups;
|
||||
for (auto &m : macros) {
|
||||
for (const auto &m : macros) {
|
||||
if (groupCount && m->IsGroup()) {
|
||||
blog(LOG_ERROR,
|
||||
"nested group detected - will delete \"%s\"",
|
||||
@@ -1234,23 +1233,28 @@ void SwitcherData::LoadMacros(obs_data_t *obj)
|
||||
}
|
||||
}
|
||||
|
||||
bool SwitcherData::CheckMacros()
|
||||
std::deque<std::shared_ptr<Macro>> &GetMacros()
|
||||
{
|
||||
bool ret = false;
|
||||
for (auto &m : macros) {
|
||||
return macros;
|
||||
}
|
||||
|
||||
bool CheckMacros()
|
||||
{
|
||||
bool matchFound = false;
|
||||
for (const auto &m : macros) {
|
||||
if (m->CeckMatch() || m->ElseActions().size() > 0) {
|
||||
ret = true;
|
||||
matchFound = true;
|
||||
// This has to be performed here for now as actions are
|
||||
// not performed immediately after checking conditions.
|
||||
if (m->SwitchesScene()) {
|
||||
switcher->macroSceneSwitched = true;
|
||||
SetMacroSwitchedScene(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return matchFound;
|
||||
}
|
||||
|
||||
bool SwitcherData::RunMacros()
|
||||
bool RunMacros()
|
||||
{
|
||||
// Create copy of macro list as elements might be removed, inserted, or
|
||||
// reordered while macros are currently being executed.
|
||||
@@ -1268,15 +1272,16 @@ bool SwitcherData::RunMacros()
|
||||
// the constructor of AdvSceneSwitcher() to complete.
|
||||
// The constructor of AdvSceneSwitcher() cannot continue however as it
|
||||
// cannot lock the main switcher mutex.
|
||||
if (GetLock()) {
|
||||
GetLock()->unlock();
|
||||
auto lock = GetLoopLock();
|
||||
if (lock) {
|
||||
lock->unlock();
|
||||
}
|
||||
|
||||
for (auto &m : runPhaseMacros) {
|
||||
if (!m || !m->ShouldRunActions()) {
|
||||
continue;
|
||||
}
|
||||
if (firstInterval && m->SkipExecOnStart()) {
|
||||
if (IsFirstInterval() && m->SkipExecOnStart()) {
|
||||
blog(LOG_INFO,
|
||||
"skip execution of macro \"%s\" at startup",
|
||||
m->Name().c_str());
|
||||
@@ -1287,15 +1292,15 @@ bool SwitcherData::RunMacros()
|
||||
blog(LOG_WARNING, "abort macro: %s", m->Name().c_str());
|
||||
}
|
||||
}
|
||||
if (GetLock()) {
|
||||
GetLock()->lock();
|
||||
if (lock) {
|
||||
lock->lock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Macro *GetMacroByName(const char *name)
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
for (const auto &m : macros) {
|
||||
if (m->Name() == name) {
|
||||
return m.get();
|
||||
}
|
||||
@@ -1311,7 +1316,7 @@ Macro *GetMacroByQString(const QString &name)
|
||||
|
||||
std::weak_ptr<Macro> GetWeakMacroByName(const char *name)
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
for (const auto &m : macros) {
|
||||
if (m->Name() == name) {
|
||||
return m;
|
||||
}
|
||||
@@ -1322,7 +1327,7 @@ std::weak_ptr<Macro> GetWeakMacroByName(const char *name)
|
||||
|
||||
void InvalidateMacroTempVarValues()
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
for (const auto &m : macros) {
|
||||
m->InvalidateTempVarValues();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +202,11 @@ private:
|
||||
QAction *_dockAction = nullptr;
|
||||
};
|
||||
|
||||
void LoadMacros(obs_data_t *obj);
|
||||
void SaveMacros(obs_data_t *obj);
|
||||
std::deque<std::shared_ptr<Macro>> &GetMacros();
|
||||
bool CheckMacros();
|
||||
bool RunMacros();
|
||||
Macro *GetMacroByName(const char *name);
|
||||
Macro *GetMacroByQString(const QString &name);
|
||||
std::weak_ptr<Macro> GetWeakMacroByName(const char *name);
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "midi-helpers.hpp"
|
||||
|
||||
#include <utility.hpp>
|
||||
#include <log-helper.hpp>
|
||||
#include <obs-module-helper.hpp>
|
||||
#include <switcher-data.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
#include <sync-helpers.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
static std::map<std::pair<MidiDeviceType, int>, MidiDeviceInstance *>
|
||||
SetupMidiMessageVector()
|
||||
{
|
||||
GetSwitcher()->AddIntervalResetStep(
|
||||
AddIntervalResetStep(
|
||||
MidiDeviceInstance::ClearMessageBuffersOfAllDevices);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <log-helper.hpp>
|
||||
#include <switcher-data.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -364,8 +364,7 @@ TwitchChatConnection::~TwitchChatConnection()
|
||||
|
||||
static bool setupChatMessageClear()
|
||||
{
|
||||
GetSwitcher()->AddIntervalResetStep(
|
||||
&TwitchChatConnection::ClearAllMessages);
|
||||
AddIntervalResetStep(&TwitchChatConnection::ClearAllMessages);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <log-helper.hpp>
|
||||
#include <switcher-data.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -58,7 +58,7 @@ EventSub::~EventSub()
|
||||
|
||||
static bool setupEventSubMessageClear()
|
||||
{
|
||||
GetSwitcher()->AddIntervalResetStep(&EventSub::ClearAllEvents);
|
||||
AddIntervalResetStep(&EventSub::ClearAllEvents);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
#include "token.hpp"
|
||||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <switcher-data.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
#include <log-helper.hpp>
|
||||
#include <obs-module-helper.hpp>
|
||||
#include <utility.hpp>
|
||||
#include <QScrollArea>
|
||||
#include <QDesktopServices>
|
||||
#include <QGroupBox>
|
||||
#include <QUrl>
|
||||
|
||||
namespace advss {
|
||||
|
||||
static const int tokenGrabberPort = 8080;
|
||||
|
||||
static std::deque<std::shared_ptr<Item>> twitchTokens;
|
||||
|
||||
const std::unordered_map<std::string, std::string> TokenOption::_apiIdToLocale{
|
||||
@@ -76,8 +82,8 @@ static void loadConnections(obs_data_t *obj);
|
||||
|
||||
bool setupTwitchTokenSupport()
|
||||
{
|
||||
GetSwitcher()->AddSaveStep(saveConnections);
|
||||
GetSwitcher()->AddLoadStep(loadConnections);
|
||||
AddSaveStep(saveConnections);
|
||||
AddLoadStep(loadConnections);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -605,7 +611,7 @@ static std::string generateScopeString(const std::set<TokenOption> &options)
|
||||
|
||||
static std::string getHtml(const QString &redirect)
|
||||
{
|
||||
const char *html = R"(
|
||||
QString html = R"(
|
||||
<html>
|
||||
<head>
|
||||
<title>Advanced scene switcher</title>
|
||||
@@ -617,17 +623,18 @@ static std::string getHtml(const QString &redirect)
|
||||
if (document.location.hash && document.location.hash != '') {
|
||||
var parsedHash = new URLSearchParams(window.location.hash.slice(1));
|
||||
if (parsedHash.get('access_token')) {
|
||||
window.location.replace(`http://localhost:8080/token?access_token=${parsedHash.get('access_token')}&state=${parsedHash.get('state')}`);
|
||||
window.location.replace(`http://localhost:%1/token?access_token=${parsedHash.get('access_token')}&state=${parsedHash.get('state')}`);
|
||||
output.textContent = 'It is safe to close this window';
|
||||
}
|
||||
} else {
|
||||
window.location.replace('%1');
|
||||
window.location.replace('%2');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>)";
|
||||
|
||||
return QString(html).arg(redirect).toStdString();
|
||||
return html.arg(QString::number(tokenGrabberPort), redirect)
|
||||
.toStdString();
|
||||
}
|
||||
|
||||
void TwitchTokenSettingsDialog::RequestToken()
|
||||
@@ -722,13 +729,16 @@ void TokenGrabberThread::run()
|
||||
|
||||
// Generate URI to request token
|
||||
auto state = generateStateString();
|
||||
auto getTokenURI = "https://id.twitch.tv/oauth2/authorize"
|
||||
"?response_type=token"
|
||||
"&client_id=" +
|
||||
QString(GetClientID()) +
|
||||
"&redirect_uri=http://localhost:8080/auth"
|
||||
"&scope=" +
|
||||
_scope + "&state=" + QString::fromStdString(state);
|
||||
QString getTokenURI =
|
||||
("https://id.twitch.tv/oauth2/authorize"
|
||||
"?response_type=token"
|
||||
"&client_id=" +
|
||||
QString(GetClientID()) +
|
||||
"&redirect_uri=http://localhost:%1"
|
||||
"/auth"
|
||||
"&scope=" +
|
||||
_scope + "&state=" + QString::fromStdString(state))
|
||||
.arg(QString::number(tokenGrabberPort));
|
||||
|
||||
// Setup server receiving token string
|
||||
auto html = getHtml(getTokenURI);
|
||||
@@ -787,8 +797,19 @@ void TokenGrabberThread::run()
|
||||
|
||||
// Start the server and wait
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
_serverThread =
|
||||
std::thread([this]() { _server.listen("localhost", 8080); });
|
||||
_serverThread = std::thread([this]() {
|
||||
if (!_server.bind_to_port("localhost", tokenGrabberPort, 0)) {
|
||||
blog(LOG_WARNING,
|
||||
"Failed to bind token server to localhost %d!",
|
||||
tokenGrabberPort);
|
||||
return;
|
||||
}
|
||||
if (!_server.listen_after_bind()) {
|
||||
blog(LOG_WARNING, "Token server failed to listen()!");
|
||||
return;
|
||||
}
|
||||
vblog(LOG_INFO, "Token server stopped!");
|
||||
});
|
||||
auto time = std::chrono::high_resolution_clock::now() +
|
||||
std::chrono::seconds(_timeout);
|
||||
while (!_stopWaiting) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "macro-condition-video.hpp"
|
||||
|
||||
#include <macro-condition-edit.hpp>
|
||||
#include <switcher-data.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
#include <utility.hpp>
|
||||
|
||||
#include <QFileDialog>
|
||||
@@ -177,8 +177,8 @@ bool MacroConditionVideo::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_video.Load(obj);
|
||||
_condition =
|
||||
static_cast<VideoCondition>(obs_data_get_int(obj, "condition"));
|
||||
SetCondition(static_cast<VideoCondition>(
|
||||
obs_data_get_int(obj, "condition")));
|
||||
_file = obs_data_get_string(obj, "filePath");
|
||||
_blockUntilScreenshotDone =
|
||||
obs_data_get_bool(obj, "blockUntilScreenshotDone");
|
||||
@@ -215,8 +215,15 @@ void MacroConditionVideo::GetScreenshot(bool blocking)
|
||||
{
|
||||
auto source = obs_weak_source_get_source(_video.GetVideo());
|
||||
_screenshotData.~ScreenshotHelper();
|
||||
new (&_screenshotData)
|
||||
ScreenshotHelper(source, blocking, GetSwitcher()->interval);
|
||||
QRect screenshotArea;
|
||||
if (_areaParameters.enable && _condition != VideoCondition::NO_IMAGE) {
|
||||
screenshotArea.setRect(_areaParameters.area.x,
|
||||
_areaParameters.area.y,
|
||||
_areaParameters.area.width,
|
||||
_areaParameters.area.height);
|
||||
}
|
||||
new (&_screenshotData) ScreenshotHelper(source, screenshotArea,
|
||||
blocking, GetIntervalValue());
|
||||
obs_source_release(source);
|
||||
_getNextScreenshot = false;
|
||||
}
|
||||
@@ -261,6 +268,12 @@ bool MacroConditionVideo::SetLanguage(const std::string &language)
|
||||
return _ocrParameters.SetLanguageCode(language);
|
||||
}
|
||||
|
||||
void MacroConditionVideo::SetCondition(VideoCondition condition)
|
||||
{
|
||||
_condition = condition;
|
||||
SetupTempVars();
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::ScreenshotContainsPattern()
|
||||
{
|
||||
cv::Mat result;
|
||||
@@ -269,9 +282,12 @@ bool MacroConditionVideo::ScreenshotContainsPattern()
|
||||
_patternMatchParameters.useAlphaAsMask,
|
||||
_patternMatchParameters.matchMode);
|
||||
if (result.total() == 0) {
|
||||
SetTempVarValue("patternCount", "0");
|
||||
return false;
|
||||
}
|
||||
return countNonZero(result) > 0;
|
||||
const auto count = countNonZero(result);
|
||||
SetTempVarValue("patternCount", std::to_string(count));
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::OutputChanged()
|
||||
@@ -300,12 +316,15 @@ bool MacroConditionVideo::ScreenshotContainsObject()
|
||||
_objMatchParameters.minNeighbors,
|
||||
_objMatchParameters.minSize.CV(),
|
||||
_objMatchParameters.maxSize.CV());
|
||||
return objects.size() > 0;
|
||||
const auto count = objects.size();
|
||||
SetTempVarValue("objectCount", std::to_string(count));
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::CheckBrightnessThreshold()
|
||||
{
|
||||
_currentBrightness = GetAvgBrightness(_screenshotData.image) / 255.;
|
||||
SetTempVarValue("brightness", std::to_string(_currentBrightness));
|
||||
return _currentBrightness > _brightnessThreshold;
|
||||
}
|
||||
|
||||
@@ -318,6 +337,7 @@ bool MacroConditionVideo::CheckOCR()
|
||||
auto text = RunOCR(_ocrParameters.GetOCR(), _screenshotData.image,
|
||||
_ocrParameters.color, _ocrParameters.colorThreshold);
|
||||
SetVariableValue(text);
|
||||
SetTempVarValue("text", text);
|
||||
if (!_ocrParameters.regex.Enabled()) {
|
||||
return text == std::string(_ocrParameters.text);
|
||||
}
|
||||
@@ -332,21 +352,22 @@ bool MacroConditionVideo::CheckOCR()
|
||||
|
||||
bool MacroConditionVideo::CheckColor()
|
||||
{
|
||||
return ContainsPixelsInColorRange(_screenshotData.image,
|
||||
_colorParameters.color,
|
||||
_colorParameters.colorThreshold,
|
||||
_colorParameters.matchThreshold);
|
||||
const bool ret = ContainsPixelsInColorRange(
|
||||
_screenshotData.image, _colorParameters.color,
|
||||
_colorParameters.colorThreshold,
|
||||
_colorParameters.matchThreshold);
|
||||
// Way too slow for now
|
||||
//SetTempVarValue("dominantColor", GetDominantColor(_screenshotData.image, 3)
|
||||
// .name(QColor::HexArgb)
|
||||
// .toStdString());
|
||||
SetTempVarValue("color", GetAverageColor(_screenshotData.image)
|
||||
.name(QColor::HexArgb)
|
||||
.toStdString());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::Compare()
|
||||
{
|
||||
if (_areaParameters.enable && _condition != VideoCondition::NO_IMAGE) {
|
||||
_screenshotData.image = _screenshotData.image.copy(
|
||||
_areaParameters.area.x, _areaParameters.area.y,
|
||||
_areaParameters.area.width,
|
||||
_areaParameters.area.height);
|
||||
}
|
||||
|
||||
if (_condition != VideoCondition::OCR) {
|
||||
SetVariableValue("");
|
||||
}
|
||||
@@ -378,6 +399,58 @@ bool MacroConditionVideo::Compare()
|
||||
return false;
|
||||
}
|
||||
|
||||
void MacroConditionVideo::SetupTempVars()
|
||||
{
|
||||
MacroCondition::SetupTempVars();
|
||||
switch (_condition) {
|
||||
case VideoCondition::PATTERN:
|
||||
AddTempvar(
|
||||
"patternCount",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.patternCount"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.patternCount.description"));
|
||||
break;
|
||||
case VideoCondition::OBJECT:
|
||||
AddTempvar(
|
||||
"objectCount",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.objectCount"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.objectCount.description"));
|
||||
break;
|
||||
case VideoCondition::BRIGHTNESS:
|
||||
AddTempvar(
|
||||
"brightness",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.brightness"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.brightness.description"));
|
||||
break;
|
||||
case VideoCondition::OCR:
|
||||
AddTempvar(
|
||||
"text",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.video.text"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.text.description"));
|
||||
break;
|
||||
case VideoCondition::COLOR:
|
||||
AddTempvar(
|
||||
"color",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.video.color"),
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.video.color.description"));
|
||||
break;
|
||||
case VideoCondition::MATCH:
|
||||
case VideoCondition::DIFFER:
|
||||
case VideoCondition::HAS_NOT_CHANGED:
|
||||
case VideoCondition::HAS_CHANGED:
|
||||
case VideoCondition::NO_IMAGE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void populateVideoInputSelection(QComboBox *list)
|
||||
{
|
||||
for (const auto &[_, name] : videoInputTypes) {
|
||||
@@ -1037,9 +1110,9 @@ MacroConditionVideoEdit::MacroConditionVideoEdit(
|
||||
"AdvSceneSwitcher.condition.video.patternMatchMode.tip"));
|
||||
populatePatternMatchModeSelection(_patternMatchMode);
|
||||
|
||||
_throttleCount->setMinimum(1 * GetSwitcher()->interval);
|
||||
_throttleCount->setMaximum(10 * GetSwitcher()->interval);
|
||||
_throttleCount->setSingleStep(GetSwitcher()->interval);
|
||||
_throttleCount->setMinimum(1 * GetIntervalValue());
|
||||
_throttleCount->setMaximum(10 * GetIntervalValue());
|
||||
_throttleCount->setSingleStep(GetIntervalValue());
|
||||
|
||||
_brightness->setSizePolicy(QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::Preferred);
|
||||
@@ -1155,7 +1228,7 @@ void MacroConditionVideoEdit::UpdatePreviewTooltip()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!requiresFileInput(_entryData->_condition)) {
|
||||
if (!requiresFileInput(_entryData->GetCondition())) {
|
||||
this->setToolTip("");
|
||||
return;
|
||||
}
|
||||
@@ -1224,7 +1297,7 @@ void MacroConditionVideoEdit::ConditionChanged(int cond)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_condition = static_cast<VideoCondition>(cond);
|
||||
_entryData->SetCondition(static_cast<VideoCondition>(cond));
|
||||
_entryData->ResetLastMatch();
|
||||
SetWidgetVisibility();
|
||||
|
||||
@@ -1239,7 +1312,7 @@ void MacroConditionVideoEdit::ConditionChanged(int cond)
|
||||
_previewDialog.PatternMatchParametersChanged(
|
||||
_entryData->_patternMatchParameters);
|
||||
|
||||
if (_entryData->_condition == VideoCondition::OBJECT) {
|
||||
if (_entryData->GetCondition() == VideoCondition::OBJECT) {
|
||||
auto path = _entryData->GetModelDataPath();
|
||||
_entryData->_objMatchParameters.cascade =
|
||||
initObjectCascade(path);
|
||||
@@ -1434,7 +1507,7 @@ void MacroConditionVideoEdit::ThrottleCountChanged(int value)
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_throttleCount = value / GetSwitcher()->interval;
|
||||
_entryData->_throttleCount = value / GetIntervalValue();
|
||||
}
|
||||
|
||||
void MacroConditionVideoEdit::ShowMatchClicked()
|
||||
@@ -1482,27 +1555,28 @@ void MacroConditionVideoEdit::SetWidgetVisibility()
|
||||
_sources->setVisible(_entryData->_video.type ==
|
||||
VideoInput::Type::SOURCE);
|
||||
_scenes->setVisible(_entryData->_video.type == VideoInput::Type::SCENE);
|
||||
_imagePath->setVisible(requiresFileInput(_entryData->_condition));
|
||||
_imagePath->setVisible(requiresFileInput(_entryData->GetCondition()));
|
||||
_usePatternForChangedCheck->setVisible(
|
||||
patternControlIsOptional(_entryData->_condition));
|
||||
_patternThreshold->setVisible(needsThreshold(_entryData->_condition));
|
||||
_useAlphaAsMask->setVisible(_entryData->_condition ==
|
||||
patternControlIsOptional(_entryData->GetCondition()));
|
||||
_patternThreshold->setVisible(
|
||||
needsThreshold(_entryData->GetCondition()));
|
||||
_useAlphaAsMask->setVisible(_entryData->GetCondition() ==
|
||||
VideoCondition::PATTERN);
|
||||
SetLayoutVisible(_patternMatchModeLayout,
|
||||
_entryData->_condition == VideoCondition::PATTERN);
|
||||
_brightness->setVisible(_entryData->_condition ==
|
||||
_entryData->GetCondition() == VideoCondition::PATTERN);
|
||||
_brightness->setVisible(_entryData->GetCondition() ==
|
||||
VideoCondition::BRIGHTNESS);
|
||||
_showMatch->setVisible(needsShowMatch(_entryData->_condition));
|
||||
_ocr->setVisible(_entryData->_condition == VideoCondition::OCR);
|
||||
_objectDetect->setVisible(_entryData->_condition ==
|
||||
_showMatch->setVisible(needsShowMatch(_entryData->GetCondition()));
|
||||
_ocr->setVisible(_entryData->GetCondition() == VideoCondition::OCR);
|
||||
_objectDetect->setVisible(_entryData->GetCondition() ==
|
||||
VideoCondition::OBJECT);
|
||||
_color->setVisible(_entryData->_condition == VideoCondition::COLOR);
|
||||
_color->setVisible(_entryData->GetCondition() == VideoCondition::COLOR);
|
||||
SetLayoutVisible(_throttleControlLayout,
|
||||
needsThrottleControls(_entryData->_condition));
|
||||
_area->setVisible(needsAreaControls(_entryData->_condition));
|
||||
needsThrottleControls(_entryData->GetCondition()));
|
||||
_area->setVisible(needsAreaControls(_entryData->GetCondition()));
|
||||
|
||||
if (_entryData->_condition == VideoCondition::HAS_CHANGED ||
|
||||
_entryData->_condition == VideoCondition::HAS_NOT_CHANGED) {
|
||||
if (_entryData->GetCondition() == VideoCondition::HAS_CHANGED ||
|
||||
_entryData->GetCondition() == VideoCondition::HAS_NOT_CHANGED) {
|
||||
_patternThreshold->setVisible(
|
||||
_entryData->_patternMatchParameters.useForChangedCheck);
|
||||
SetLayoutVisible(
|
||||
@@ -1528,7 +1602,7 @@ void MacroConditionVideoEdit::SetupPreviewDialogParams()
|
||||
_previewDialog.VideoSelectionChanged(_entryData->_video);
|
||||
_previewDialog.AreaParametersChanged(_entryData->_areaParameters);
|
||||
_previewDialog.ConditionChanged(
|
||||
static_cast<int>(_entryData->_condition));
|
||||
static_cast<int>(_entryData->GetCondition()));
|
||||
}
|
||||
|
||||
void MacroConditionVideoEdit::UpdateEntryData()
|
||||
@@ -1541,7 +1615,8 @@ void MacroConditionVideoEdit::UpdateEntryData()
|
||||
static_cast<int>(_entryData->_video.type));
|
||||
_scenes->SetScene(_entryData->_video.scene);
|
||||
_sources->SetSource(_entryData->_video.source);
|
||||
_condition->setCurrentIndex(static_cast<int>(_entryData->_condition));
|
||||
_condition->setCurrentIndex(
|
||||
static_cast<int>(_entryData->GetCondition()));
|
||||
_reduceLatency->setChecked(_entryData->_blockUntilScreenshotDone);
|
||||
_imagePath->SetPath(QString::fromStdString(_entryData->_file));
|
||||
_usePatternForChangedCheck->setChecked(
|
||||
@@ -1554,7 +1629,7 @@ void MacroConditionVideoEdit::UpdateEntryData()
|
||||
_entryData->_patternMatchParameters.matchMode));
|
||||
_throttleEnable->setChecked(_entryData->_throttleEnabled);
|
||||
_throttleCount->setValue(_entryData->_throttleCount *
|
||||
GetSwitcher()->interval);
|
||||
GetIntervalValue());
|
||||
UpdatePreviewTooltip();
|
||||
SetupPreviewDialogParams();
|
||||
SetWidgetVisibility();
|
||||
|
||||
@@ -45,8 +45,10 @@ public:
|
||||
void SetPageSegMode(tesseract::PageSegMode);
|
||||
bool SetLanguage(const std::string &);
|
||||
|
||||
void SetCondition(VideoCondition);
|
||||
VideoCondition GetCondition() const { return _condition; }
|
||||
|
||||
VideoInput _video;
|
||||
VideoCondition _condition = VideoCondition::MATCH;
|
||||
std::string _file = obs_module_text("AdvSceneSwitcher.enterPath");
|
||||
// Enabling this will reduce matching latency, but slow down the
|
||||
// the condition checks of all macros overall.
|
||||
@@ -74,6 +76,10 @@ private:
|
||||
bool Compare();
|
||||
bool CheckShouldBeSkipped();
|
||||
|
||||
void SetupTempVars();
|
||||
|
||||
VideoCondition _condition = VideoCondition::MATCH;
|
||||
|
||||
bool _getNextScreenshot = true;
|
||||
ScreenshotHelper _screenshotData;
|
||||
QImage _matchImage;
|
||||
|
||||
@@ -225,6 +225,61 @@ bool ContainsPixelsInColorRange(const QImage &image, const QColor &color,
|
||||
return matchPercentage >= totalPixelMatchThreshold;
|
||||
}
|
||||
|
||||
QColor GetAverageColor(const QImage &img)
|
||||
{
|
||||
if (img.isNull()) {
|
||||
return QColor();
|
||||
}
|
||||
|
||||
auto image = QImageToMat(img);
|
||||
cv::Scalar meanColor = cv::mean(image);
|
||||
int averageBlue = cvRound(meanColor[0]);
|
||||
int averageGreen = cvRound(meanColor[1]);
|
||||
int averageRed = cvRound(meanColor[2]);
|
||||
|
||||
return QColor(averageRed, averageGreen, averageBlue);
|
||||
}
|
||||
|
||||
QColor GetDominantColor(const QImage &img, int k)
|
||||
{
|
||||
if (img.isNull()) {
|
||||
return QColor();
|
||||
}
|
||||
|
||||
auto image = QImageToMat(img);
|
||||
cv::Mat reshapedImage = image.reshape(1, image.rows * image.cols);
|
||||
reshapedImage.convertTo(reshapedImage, CV_32F);
|
||||
|
||||
cv::mean(reshapedImage);
|
||||
|
||||
// Apply k-means clustering to group similar colors
|
||||
cv::TermCriteria criteria(
|
||||
cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 100, 0.2);
|
||||
cv::Mat labels, centers;
|
||||
cv::kmeans(reshapedImage, k, labels, criteria, 1,
|
||||
cv::KMEANS_RANDOM_CENTERS, centers);
|
||||
|
||||
// Find the dominant color
|
||||
// Center of the cluster with the largest number of pixels
|
||||
cv::Mat counts = cv::Mat::zeros(1, k, CV_32SC1);
|
||||
for (int i = 0; i < labels.rows; i++) {
|
||||
counts.at<int>(0, labels.at<int>(i))++;
|
||||
}
|
||||
|
||||
cv::Point max_loc;
|
||||
cv::minMaxLoc(counts, nullptr, nullptr, nullptr, &max_loc);
|
||||
try {
|
||||
cv::Scalar dominantColor = centers.at<cv::Scalar>(max_loc.y);
|
||||
const int blue = cv::saturate_cast<int>(dominantColor.val[0]);
|
||||
const int green = cv::saturate_cast<int>(dominantColor.val[1]);
|
||||
const int red = cv::saturate_cast<int>(dominantColor.val[2]);
|
||||
const int alpha = cv::saturate_cast<int>(dominantColor.val[3]);
|
||||
return QColor(red, green, blue, alpha);
|
||||
} catch (...) {
|
||||
}
|
||||
return QColor();
|
||||
}
|
||||
|
||||
// Assumption is that QImage uses Format_RGBA8888.
|
||||
// Conversion from: https://github.com/dbzhang800/QtOpenCV
|
||||
cv::Mat QImageToMat(const QImage &img)
|
||||
|
||||
@@ -66,6 +66,8 @@ std::string RunOCR(tesseract::TessBaseAPI *, const QImage &, const QColor &,
|
||||
bool ContainsPixelsInColorRange(const QImage &image, const QColor &color,
|
||||
double colorDeviationThreshold,
|
||||
double totalPixelMatchThreshold);
|
||||
QColor GetAverageColor(const QImage &img);
|
||||
QColor GetDominantColor(const QImage &image, int k);
|
||||
cv::Mat QImageToMat(const QImage &img);
|
||||
QImage MatToQImage(const cv::Mat &mat);
|
||||
|
||||
|
||||
@@ -255,7 +255,13 @@ void PreviewImage::CreateImage(const VideoInput &video, PreviewType type,
|
||||
VideoCondition condition)
|
||||
{
|
||||
auto source = obs_weak_source_get_source(video.GetVideo());
|
||||
ScreenshotHelper screenshot(source, true);
|
||||
QRect screenshotArea;
|
||||
if (areaParams.enable && type == PreviewType::SHOW_MATCH) {
|
||||
screenshotArea.setRect(areaParams.area.x, areaParams.area.y,
|
||||
areaParams.area.width,
|
||||
areaParams.area.height);
|
||||
}
|
||||
ScreenshotHelper screenshot(source, screenshotArea, true);
|
||||
obs_source_release(source);
|
||||
|
||||
if (!video.ValidSelection() || !screenshot.done) {
|
||||
@@ -274,11 +280,6 @@ void PreviewImage::CreateImage(const VideoInput &video, PreviewType type,
|
||||
|
||||
if (type == PreviewType::SHOW_MATCH) {
|
||||
std::unique_lock<std::mutex> lock(_mtx);
|
||||
if (areaParams.enable) {
|
||||
screenshot.image = screenshot.image.copy(
|
||||
areaParams.area.x, areaParams.area.y,
|
||||
areaParams.area.width, areaParams.area.height);
|
||||
}
|
||||
// Will emit status label update
|
||||
MarkMatch(screenshot.image, patternMatchParams,
|
||||
patternImageData, objDetectParams, ocrParams,
|
||||
|
||||
@@ -383,6 +383,9 @@ static std::map<HotkeyType, CGKeyCode> keyTable = {
|
||||
{HotkeyType::Key_8, kVK_ANSI_8},
|
||||
{HotkeyType::Key_9, kVK_ANSI_9},
|
||||
|
||||
// Other
|
||||
// Not sure which key to use for tilde
|
||||
|
||||
{HotkeyType::Key_F1, kVK_F1},
|
||||
{HotkeyType::Key_F2, kVK_F2},
|
||||
{HotkeyType::Key_F3, kVK_F3},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "status-control.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <obs-module.h>
|
||||
@@ -51,10 +51,10 @@ StatusControl::StatusControl(QWidget *parent, bool noLayout)
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
if (switcher->stop) {
|
||||
SetStopped();
|
||||
} else {
|
||||
if (PluginIsRunning()) {
|
||||
SetStarted();
|
||||
} else {
|
||||
SetStopped();
|
||||
}
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdateStatus()));
|
||||
_timer.start(1000);
|
||||
@@ -62,22 +62,18 @@ StatusControl::StatusControl(QWidget *parent, bool noLayout)
|
||||
|
||||
void StatusControl::ButtonClicked()
|
||||
{
|
||||
if (switcher->th && switcher->th->isRunning()) {
|
||||
switcher->Stop();
|
||||
if (PluginIsRunning()) {
|
||||
StopPlugin();
|
||||
SetStopped();
|
||||
} else {
|
||||
switcher->Start();
|
||||
StartPlugin();
|
||||
SetStarted();
|
||||
}
|
||||
}
|
||||
|
||||
void StatusControl::UpdateStatus()
|
||||
{
|
||||
if (!switcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (switcher->th && switcher->th->isRunning()) {
|
||||
if (PluginIsRunning()) {
|
||||
if (!_setToStopped) {
|
||||
return;
|
||||
}
|
||||
@@ -104,7 +100,7 @@ void StatusControl::SetStopped()
|
||||
_button->setText(
|
||||
obs_module_text("AdvSceneSwitcher.generalTab.status.start"));
|
||||
_status->setText(obs_module_text("AdvSceneSwitcher.status.inactive"));
|
||||
if (!switcher->disableHints) {
|
||||
if (HighlightUIElementsEnabled()) {
|
||||
_pulse = PulseWidget(_status, QColor(Qt::red),
|
||||
QColor(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ std::mutex *GetSwitcherMutex()
|
||||
return switcher ? &switcher->m : nullptr;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> *GetSwitcherLoopLock()
|
||||
{
|
||||
return switcher ? switcher->mainLoopLock : nullptr;
|
||||
}
|
||||
|
||||
bool VerboseLoggingEnabled()
|
||||
{
|
||||
return switcher ? switcher->verbose : false;
|
||||
@@ -45,7 +50,7 @@ void SwitcherData::Prune()
|
||||
}
|
||||
|
||||
if (nonMatchingScene && !WeakSourceValid(nonMatchingScene)) {
|
||||
switchIfNotMatching = NoMatch::NO_SWITCH;
|
||||
switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
|
||||
nonMatchingScene = nullptr;
|
||||
}
|
||||
|
||||
@@ -168,8 +173,13 @@ void SwitcherData::SaveVersion(obs_data_t *obj,
|
||||
obs_data_set_string(obj, "version", currentVersion.c_str());
|
||||
}
|
||||
|
||||
void SwitcherData::AddIntervalResetStep(std::function<void()> function)
|
||||
void SwitcherData::AddIntervalResetStep(std::function<void()> function,
|
||||
bool tryLock)
|
||||
{
|
||||
if (!tryLock) {
|
||||
resetIntervalSteps.emplace_back(function);
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
resetIntervalSteps.emplace_back(function);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
|
||||
#include "macro-properties.hpp"
|
||||
#include "duration-control.hpp"
|
||||
#include "curl-helper.hpp"
|
||||
#include "priority-helper.hpp"
|
||||
#include "log-helper.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <vector>
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <mutex>
|
||||
#include <QDateTime>
|
||||
#include <QThread>
|
||||
#include <curl/curl.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace advss {
|
||||
@@ -46,6 +45,7 @@ class SwitcherData;
|
||||
extern SwitcherData *switcher;
|
||||
SwitcherData *GetSwitcher();
|
||||
std::mutex *GetSwitcherMutex();
|
||||
std::unique_lock<std::mutex> *GetSwitcherLoopLock();
|
||||
bool VerboseLoggingEnabled();
|
||||
|
||||
class SwitcherData {
|
||||
@@ -53,7 +53,6 @@ public:
|
||||
void Thread();
|
||||
void Start();
|
||||
void Stop();
|
||||
std::unique_lock<std::mutex> *GetLock() { return mainLoopLock; }
|
||||
|
||||
const char *Translate(const char *);
|
||||
obs_module_t *GetModule();
|
||||
@@ -67,30 +66,22 @@ public:
|
||||
void AddSaveStep(std::function<void(obs_data_t *)>);
|
||||
void AddLoadStep(std::function<void(obs_data_t *)>);
|
||||
void AddPostLoadStep(std::function<void()>);
|
||||
void AddIntervalResetStep(std::function<void()>);
|
||||
void AddIntervalResetStep(std::function<void()>, bool lock = true);
|
||||
bool CheckForMatch(OBSWeakSource &scene, OBSWeakSource &transition,
|
||||
int &linger, bool &setPreviousSceneAsMatch,
|
||||
bool ¯oMatch);
|
||||
bool CheckMacros();
|
||||
bool RunMacros();
|
||||
void CheckNoMatchSwitch(bool &match, OBSWeakSource &scene,
|
||||
OBSWeakSource &transition, int &sleep);
|
||||
|
||||
/* --- Start of saving / loading section --- */
|
||||
|
||||
void SaveSettings(obs_data_t *obj);
|
||||
void SaveMacros(obs_data_t *obj);
|
||||
void SaveConnections(obs_data_t *obj);
|
||||
void SaveVariables(obs_data_t *obj);
|
||||
void SaveGeneralSettings(obs_data_t *obj);
|
||||
void SaveHotkeys(obs_data_t *obj);
|
||||
void SaveUISettings(obs_data_t *obj);
|
||||
void SaveVersion(obs_data_t *obj, const std::string ¤tVersion);
|
||||
|
||||
void LoadSettings(obs_data_t *obj);
|
||||
void LoadMacros(obs_data_t *obj);
|
||||
void LoadConnections(obs_data_t *obj);
|
||||
void LoadVariables(obs_data_t *obj);
|
||||
void LoadGeneralSettings(obs_data_t *obj);
|
||||
void LoadHotkeys(obs_data_t *obj);
|
||||
void LoadUISettings(obs_data_t *obj);
|
||||
@@ -111,9 +102,6 @@ public:
|
||||
std::unique_lock<std::mutex> *mainLoopLock = nullptr;
|
||||
bool stop = false;
|
||||
std::condition_variable cv;
|
||||
std::condition_variable macroWaitCv;
|
||||
std::atomic_bool abortMacroWait = {false};
|
||||
std::condition_variable macroTransitionCv;
|
||||
|
||||
std::vector<std::function<void(obs_data_t *)>> saveSteps;
|
||||
std::vector<std::function<void(obs_data_t *)>> loadSteps;
|
||||
@@ -123,28 +111,20 @@ public:
|
||||
bool firstBoot = true;
|
||||
bool transitionActive = false;
|
||||
bool sceneColletionStop = false;
|
||||
bool replayBufferSaved = false;
|
||||
bool obsIsShuttingDown = false;
|
||||
bool firstInterval = true;
|
||||
bool firstIntervalAfterStop = true;
|
||||
int shutdownConditionCount = 0;
|
||||
bool startupLoadDone = false;
|
||||
|
||||
obs_source_t *waitScene = nullptr;
|
||||
OBSWeakSource currentScene = nullptr;
|
||||
OBSWeakSource previousScene = nullptr;
|
||||
std::chrono::high_resolution_clock::time_point lastSceneChangeTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastTransitionEndTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastStreamStartingTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastStreamStoppingTime{};
|
||||
std::chrono::high_resolution_clock::time_point lastMatchTime;
|
||||
|
||||
/* --- Start of General tab section --- */
|
||||
|
||||
int interval = default_interval;
|
||||
OBSWeakSource nonMatchingScene;
|
||||
enum class NoMatch { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 };
|
||||
NoMatch switchIfNotMatching = NoMatch::NO_SWITCH;
|
||||
NoMatchBehavior switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
|
||||
Duration noMatchDelay;
|
||||
enum class StartupBehavior { PERSIST = 0, START = 1, STOP = 2 };
|
||||
StartupBehavior startupBehavior = StartupBehavior::PERSIST;
|
||||
@@ -163,27 +143,9 @@ public:
|
||||
|
||||
/* --- End of General tab section --- */
|
||||
|
||||
struct AudioFadeInfo {
|
||||
std::atomic_bool active = {false};
|
||||
std::atomic_int id = {0};
|
||||
};
|
||||
AudioFadeInfo masterAudioFade;
|
||||
std::unordered_map<std::string, AudioFadeInfo> activeAudioFades;
|
||||
|
||||
MacroProperties macroProperties;
|
||||
std::deque<std::shared_ptr<Macro>> macros;
|
||||
bool macroSceneSwitched = false;
|
||||
|
||||
Curlhelper curl;
|
||||
std::deque<std::shared_ptr<Item>> connections;
|
||||
std::vector<std::string> websocketMessages;
|
||||
std::deque<std::shared_ptr<Item>> variables;
|
||||
|
||||
std::string lastTitle;
|
||||
std::string currentTitle;
|
||||
std::string currentForegroundProcess;
|
||||
std::pair<int, int> lastCursorPos = {0, 0};
|
||||
bool cursorPosChanged = false;
|
||||
|
||||
std::vector<int> functionNamesByPriority =
|
||||
GetDefaultFunctionPriorityList();
|
||||
|
||||
@@ -1,18 +1,33 @@
|
||||
#include "connection-manager.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "name-dialog.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <obs-module.h>
|
||||
|
||||
Q_DECLARE_METATYPE(advss::Connection *);
|
||||
|
||||
namespace advss {
|
||||
|
||||
void SwitcherData::SaveConnections(obs_data_t *obj)
|
||||
static std::deque<std::shared_ptr<Item>> connections;
|
||||
static void saveConnections(obs_data_t *obj);
|
||||
static void loadConnections(obs_data_t *obj);
|
||||
|
||||
void SetupConnectionManager()
|
||||
{
|
||||
static bool done = false;
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
AddSaveStep(saveConnections);
|
||||
AddLoadStep(loadConnections);
|
||||
done = true;
|
||||
}
|
||||
|
||||
static void saveConnections(obs_data_t *obj)
|
||||
{
|
||||
obs_data_array_t *connectionArray = obs_data_array_create();
|
||||
for (const auto &c : connections) {
|
||||
@@ -25,7 +40,7 @@ void SwitcherData::SaveConnections(obs_data_t *obj)
|
||||
obs_data_array_release(connectionArray);
|
||||
}
|
||||
|
||||
void SwitcherData::LoadConnections(obs_data_t *obj)
|
||||
static void loadConnections(obs_data_t *obj)
|
||||
{
|
||||
connections.clear();
|
||||
|
||||
@@ -192,7 +207,7 @@ Connection *GetConnectionByName(const QString &name)
|
||||
|
||||
Connection *GetConnectionByName(const std::string &name)
|
||||
{
|
||||
for (auto &con : switcher->connections) {
|
||||
for (auto &con : connections) {
|
||||
if (con->Name() == name) {
|
||||
return dynamic_cast<Connection *>(con.get());
|
||||
}
|
||||
@@ -202,7 +217,7 @@ Connection *GetConnectionByName(const std::string &name)
|
||||
|
||||
std::weak_ptr<Connection> GetWeakConnectionByName(const std::string &name)
|
||||
{
|
||||
for (const auto &c : switcher->connections) {
|
||||
for (const auto &c : connections) {
|
||||
if (c->Name() == name) {
|
||||
std::weak_ptr<Connection> wp =
|
||||
std::dynamic_pointer_cast<Connection>(c);
|
||||
@@ -226,6 +241,11 @@ std::string GetWeakConnectionName(std::weak_ptr<Connection> connection)
|
||||
return con->Name();
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<Item>> &GetConnections()
|
||||
{
|
||||
return connections;
|
||||
}
|
||||
|
||||
static bool ConnectionNameAvailable(const QString &name)
|
||||
{
|
||||
return !GetConnectionByName(name);
|
||||
@@ -244,8 +264,7 @@ static bool AskForSettingsWrapper(QWidget *parent, Item &settings)
|
||||
}
|
||||
|
||||
ConnectionSelection::ConnectionSelection(QWidget *parent)
|
||||
: ItemSelection(switcher->connections, Connection::Create,
|
||||
AskForSettingsWrapper,
|
||||
: ItemSelection(connections, Connection::Create, AskForSettingsWrapper,
|
||||
"AdvSceneSwitcher.connection.select",
|
||||
"AdvSceneSwitcher.connection.add",
|
||||
"AdvSceneSwitcher.item.nameNotAvailable",
|
||||
@@ -296,7 +315,7 @@ void ConnectionSelection::SetConnection(
|
||||
|
||||
ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
||||
const Connection &settings)
|
||||
: ItemSettingsDialog(settings, switcher->connections,
|
||||
: ItemSettingsDialog(settings, connections,
|
||||
"AdvSceneSwitcher.connection.select",
|
||||
"AdvSceneSwitcher.connection.add",
|
||||
"AdvSceneSwitcher.item.nameNotAvailable", parent),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "item-selection-helpers.hpp"
|
||||
#include "websocket-helpers.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
@@ -14,10 +15,11 @@
|
||||
#include <QGridLayout>
|
||||
#include <deque>
|
||||
#include <obs.hpp>
|
||||
#include <websocket-helpers.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
void SetupConnectionManager();
|
||||
|
||||
class ConnectionSelection;
|
||||
class ConnectionSettingsDialog;
|
||||
|
||||
@@ -69,6 +71,7 @@ Connection *GetConnectionByName(const std::string &);
|
||||
std::weak_ptr<Connection> GetWeakConnectionByName(const std::string &name);
|
||||
std::weak_ptr<Connection> GetWeakConnectionByQString(const QString &name);
|
||||
std::string GetWeakConnectionName(std::weak_ptr<Connection>);
|
||||
std::deque<std::shared_ptr<Item>> &GetConnections();
|
||||
|
||||
class ConnectionSettingsDialog : public ItemSettingsDialog {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -15,7 +15,7 @@ constexpr auto curl_library_name = "libcurl.4.dylib";
|
||||
constexpr auto curl_library_name = "libcurl.so.4";
|
||||
#endif
|
||||
|
||||
Curlhelper::Curlhelper()
|
||||
CurlHelper::CurlHelper()
|
||||
{
|
||||
if (LoadLib()) {
|
||||
_curl = _init();
|
||||
@@ -23,7 +23,7 @@ Curlhelper::Curlhelper()
|
||||
}
|
||||
}
|
||||
|
||||
Curlhelper::~Curlhelper()
|
||||
CurlHelper::~CurlHelper()
|
||||
{
|
||||
if (_lib) {
|
||||
if (_cleanup) {
|
||||
@@ -34,23 +34,46 @@ Curlhelper::~Curlhelper()
|
||||
}
|
||||
}
|
||||
|
||||
curl_slist *Curlhelper::SlistAppend(curl_slist *list, const char *string)
|
||||
CurlHelper &CurlHelper::GetInstance()
|
||||
{
|
||||
if (!_initialized) {
|
||||
static CurlHelper curl;
|
||||
return curl;
|
||||
}
|
||||
|
||||
bool CurlHelper::Initialized()
|
||||
{
|
||||
return GetInstance()._initialized;
|
||||
}
|
||||
|
||||
curl_slist *CurlHelper::SlistAppend(curl_slist *list, const char *string)
|
||||
{
|
||||
auto &curl = GetInstance();
|
||||
if (!curl._initialized) {
|
||||
return nullptr;
|
||||
}
|
||||
return _slistAppend(list, string);
|
||||
return curl._slistAppend(list, string);
|
||||
}
|
||||
|
||||
CURLcode Curlhelper::Perform()
|
||||
CURLcode CurlHelper::Perform()
|
||||
{
|
||||
if (!_initialized) {
|
||||
auto &curl = GetInstance();
|
||||
if (!curl._initialized) {
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
return _perform(_curl);
|
||||
return curl._perform(curl._curl);
|
||||
}
|
||||
|
||||
bool Curlhelper::LoadLib()
|
||||
char *CurlHelper::GetError(CURLcode code)
|
||||
{
|
||||
auto &curl = GetInstance();
|
||||
if (!curl._initialized) {
|
||||
return (char *)"CURL initialization failed";
|
||||
}
|
||||
|
||||
return curl._error(code);
|
||||
}
|
||||
|
||||
bool CurlHelper::LoadLib()
|
||||
{
|
||||
_lib = new QLibrary(curl_library_name, nullptr);
|
||||
if (Resolve()) {
|
||||
@@ -94,15 +117,17 @@ bool Curlhelper::LoadLib()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Curlhelper::Resolve()
|
||||
bool CurlHelper::Resolve()
|
||||
{
|
||||
_init = (initFunction)_lib->resolve("curl_easy_init");
|
||||
_setopt = (setOptFunction)_lib->resolve("curl_easy_setopt");
|
||||
_slistAppend = (slistAppendFunction)_lib->resolve("curl_slist_append");
|
||||
_perform = (performFunction)_lib->resolve("curl_easy_perform");
|
||||
_cleanup = (cleanupFunction)_lib->resolve("curl_easy_cleanup");
|
||||
_error = (errorFunction)_lib->resolve("curl_easy_strerror");
|
||||
|
||||
if (_init && _setopt && _slistAppend && _perform && _cleanup) {
|
||||
if (_init && _setopt && _slistAppend && _perform && _cleanup &&
|
||||
_error) {
|
||||
blog(LOG_INFO, "[adv-ss] curl loaded successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
#pragma once
|
||||
#include <curl/curl.h>
|
||||
#include <QLibrary>
|
||||
#include <atomic>
|
||||
|
||||
namespace advss {
|
||||
|
||||
typedef CURL *(*initFunction)(void);
|
||||
typedef void (*cleanupFunction)(CURL *);
|
||||
typedef CURLcode (*setOptFunction)(CURL *, CURLoption, ...);
|
||||
typedef struct curl_slist *(*slistAppendFunction)(struct curl_slist *list,
|
||||
const char *string);
|
||||
typedef CURLcode (*performFunction)(CURL *);
|
||||
|
||||
class Curlhelper {
|
||||
class CurlHelper {
|
||||
public:
|
||||
Curlhelper();
|
||||
~Curlhelper();
|
||||
|
||||
template<typename... Args> CURLcode SetOpt(CURLoption, Args...);
|
||||
struct curl_slist *SlistAppend(struct curl_slist *list,
|
||||
const char *string);
|
||||
CURLcode Perform();
|
||||
bool Initialized() { return _initialized; }
|
||||
static bool Initialized();
|
||||
template<typename... Args> static CURLcode SetOpt(CURLoption, Args...);
|
||||
static struct curl_slist *SlistAppend(struct curl_slist *list,
|
||||
const char *string);
|
||||
static CURLcode Perform();
|
||||
static char *GetError(CURLcode code);
|
||||
|
||||
private:
|
||||
CurlHelper();
|
||||
CurlHelper(const CurlHelper &) = delete;
|
||||
CurlHelper &operator=(const CurlHelper &) = delete;
|
||||
~CurlHelper();
|
||||
|
||||
typedef CURL *(*initFunction)(void);
|
||||
typedef CURLcode (*setOptFunction)(CURL *, CURLoption, ...);
|
||||
typedef struct curl_slist *(*slistAppendFunction)(
|
||||
struct curl_slist *list, const char *string);
|
||||
typedef CURLcode (*performFunction)(CURL *);
|
||||
typedef void (*cleanupFunction)(CURL *);
|
||||
typedef char *(*errorFunction)(CURLcode);
|
||||
|
||||
static CurlHelper &GetInstance();
|
||||
|
||||
bool LoadLib();
|
||||
bool Resolve();
|
||||
|
||||
@@ -31,18 +38,20 @@ private:
|
||||
slistAppendFunction _slistAppend = nullptr;
|
||||
performFunction _perform = nullptr;
|
||||
cleanupFunction _cleanup = nullptr;
|
||||
errorFunction _error = nullptr;
|
||||
CURL *_curl = nullptr;
|
||||
QLibrary *_lib;
|
||||
bool _initialized = false;
|
||||
std::atomic_bool _initialized = {false};
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
inline CURLcode Curlhelper::SetOpt(CURLoption option, Args... args)
|
||||
inline CURLcode CurlHelper::SetOpt(CURLoption option, Args... args)
|
||||
{
|
||||
if (!_initialized) {
|
||||
auto &curl = GetInstance();
|
||||
if (!curl._initialized) {
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
return _setopt(_curl, option, args...);
|
||||
return curl._setopt(curl._curl, option, args...);
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user