Compare commits

..

90 Commits
1.8.3 ... 1.12

Author SHA1 Message Date
WarmUpTill
2ce0b35921 Add volume to control to audio action 2021-05-15 09:51:20 -07:00
WarmUpTill
33d2def126 Explicitly cast enum class to int 2021-05-15 09:05:43 -07:00
WarmUpTill
c44b0a2ac2 Remove unused verbose parameter 2021-05-15 09:05:43 -07:00
WarmUpTill
3abeb936b3 Fix random order of various macro entries 2021-05-15 01:03:07 -07:00
WarmUpTill
cef513f775 Adjust plugin state macro condition id 2021-05-14 14:03:04 -07:00
WarmUpTill
a66961eac1 Add macro condition "idle" 2021-05-14 14:03:04 -07:00
WarmUpTill
92c8767e1a Move plugin state condition to end 2021-05-14 09:44:49 -07:00
WarmUpTill
5b12468a46 Add macro condition process 2021-05-14 09:44:49 -07:00
WarmUpTill
675021c284 Add Macro tab (#170)
* add action switch scene

* add window condition

* Add macro action wait

* Add macro condition region

* Add audio macro condition

* Add file based macro condition

* Add macro condition media

* Add video macro condition

* Add macro action audio

* Add macro action streaming

* Add macro action recording

* Add replay buffer macro action

* Add stream macro condition

* Add macro condition recording

* Add macro condition plugin state

* Add macro action to run an arbitrary command
2021-05-14 16:37:01 +02:00
WarmUpTill
6bf122d0e8 Add support for transition duration in switchScene() (#178) 2021-05-12 19:50:50 +02:00
Pander
8b8e479098 added system-wide Flatpak paths (#175) 2021-05-06 20:38:11 +02:00
WarmUpTill
717d41a527 Adjust default setting values of transition tab 2021-05-04 11:32:45 -07:00
WarmUpTill
ad5587e084 Fix transition overrides not restoring duration 2021-05-04 11:32:45 -07:00
WarmUpTill
f37f384b5a Move DisplayMessage() to utility.hpp 2021-05-04 11:32:45 -07:00
WarmUpTill
dad36689c4 Move AdvSSScreenshotObj to separate files 2021-05-04 11:32:45 -07:00
WarmUpTill
0bd7d004ad Reduce includes of platform specific files
This is done to avoid build issues in future.
For example previously the class "Duration" class caused build issues on
the MacOS platform due to a name conflict.
2021-05-04 11:32:45 -07:00
WarmUpTill
f8c589c7a2 Only send scene switch msg if scene was switched
This change is to avoid spamming the connected clients with scene change
messages which might not even do anything as the scene change already
took place.
Additionally it allows scene switch messages to be sent by just calling
the switchScene() function.
2021-05-04 11:32:45 -07:00
WarmUpTill
e714df7ad0 Use Duration class and DurationSelection widget 2021-05-04 11:32:45 -07:00
WarmUpTill
6277da1bbd Add Duration class and DurationSelection widget 2021-05-04 11:32:45 -07:00
WarmUpTill
1bef309264 Only try to change transition overrides if needed 2021-05-04 11:32:45 -07:00
WarmUpTill
2e1d660e17 Clean up loading of transition tab settings 2021-05-04 11:32:45 -07:00
WarmUpTill
3f492f468a Move compareIgnoringLineEnding() to utility.hpp 2021-05-04 11:32:45 -07:00
WarmUpTill
c86bba84b3 Add scene-group.hpp include to switch-generic
This is to allow easier use of generic scene switch structs and widgets
in other areas. (Macro tab)
2021-05-04 11:32:45 -07:00
WarmUpTill
c468b0698b Move definition of SwitchTargetType 2021-05-04 11:32:45 -07:00
WarmUpTill
2af82fe22a Fix ignoring match of checkSwitchInfoFromFile() if checkFileContent() does not match 2021-05-04 11:32:45 -07:00
WarmUpTill
5d720219bf Clean up transition tab save and load 2021-05-04 11:32:45 -07:00
WarmUpTill
484e1aa191 Remove unnused function 2021-05-04 11:32:45 -07:00
WarmUpTill
0fdfe757b4 Reset tab order if config is invalid 2021-05-04 11:32:45 -07:00
WarmUpTill
bc5a04651f Remove unnecessary indirection 2021-05-04 11:32:45 -07:00
WarmUpTill
d9dfc1913d Fix previous scene not working for some sequences
If a duration for a transition is used that is longer than the scene
switcher check interval it could happen that the "incorrect" previous
scene could be chosen for uninterruptible scene sequences, as at the
time the sequence check was preformed the "previous scene" variable
was not yet updated as the transition was still ongoing.
2021-05-04 11:32:45 -07:00
WarmUpTill
1310d0b3f3 Add comment 2021-05-04 11:32:45 -07:00
WarmUpTill
139df8a641 Adjust function signature
Don't pass bool by reference if not necessary.
2021-05-04 11:32:45 -07:00
WarmUpTill
acf1ae63aa Drop support for old settings format 2021-05-04 11:32:45 -07:00
WarmUpTill
041a9e7f19 Add option to set transition duration (#171) 2021-05-01 00:20:25 +02:00
Pander
427ed34a1b added Flatpak paths for Ubuntu (#172) 2021-04-27 18:35:04 +02:00
WarmUpTill
45fa4dac8f Add option "has changed" to video tab (#168) 2021-04-22 20:51:35 +02:00
WarmUpTill
e4bf5fa749 Add option to use transition overrides for transition changes (#164)
* Adjust switchScene() signature to support adjustActiveTransitionType and verbose parameters and only change the transition type if adjustActiveTransitionType, otherwise rely on transition overrides

* Add new adjustActiveTransitionType checkbox

* save and load adjustActiveTransitionType

* Add check to either enable transition type change or use of transition
overrides

* Add locale

* Adjust layout and locale
2021-04-10 19:58:17 +02:00
WarmUpTill
eb346da6f4 CI: Fix macOS build by disabling browser build (#163) 2021-04-09 20:57:35 +02:00
WarmUpTill
866480cde6 Fix crash on Linux if no ewmh is available (#159) 2021-04-07 21:03:54 +02:00
WarmUpTill
10e1c7b3a3 Resolve asio network crashes on macOS (#157)
* Reenable network tab functionality for macOS

* Set asio to b73dc1d and  websocketpp to c6d7e29
2021-04-03 22:02:42 +02:00
WarmUpTill
beb482bd5a Disable Network tab functionality on macOS (#155)
The asio library ran into issues when the obs-websocket plugin was also running leading to a crash in the obs-websocket's listen() calls.

As the use obs-websocket plugin is more widespread than the use of the advanced scene switcher the network tab functionality will be disabled for macOS for the time being.
2021-04-03 18:52:16 +02:00
WarmUpTill
e561d378dd CI: Disable PipeWire on Ubuntu (#156) 2021-04-03 12:43:52 +02:00
WarmUpTill
73ce88e2f0 Add option to save window size and position (#154) 2021-04-03 11:55:42 +02:00
WarmUpTill
dfccc4b16d Add network tab (#149)
The network tab allows you to open a web-socket or connect to web-socket to synchronize the active scene between two or more instances of OBS.
The functionality is mostly based on https://github.com/Palakis/obs-websocket.

An OBS instance running a server will send its currently active scene to all connected clients on scene change.
By default all scene switches will trigger a message to be sent to all clients, but you also have the option to limit sending these messages only when an automated scene change is triggered by the advanced scene switcher.
2021-03-24 20:51:22 +01:00
WarmUpTill
b0ef1fee71 Fix window check always testing for focus (#152) 2021-03-22 23:06:44 +01:00
WarmUpTill
1ef8ce4b4a Resolve Qt runtime warning by renaming function. (#151) 2021-03-22 22:31:29 +01:00
WarmUpTill
1bf4bff014 Merge pull request #150 from WarmUpTill/CI
CI: Improve format check and init submodules for build
2021-03-21 21:48:21 +01:00
WarmUpTill
4b6e00b2b2 CI: Init submodules for build 2021-03-21 21:39:11 +01:00
WarmUpTill
c99cbb0c0f CI: Improve format check.
The format check used to check too many files, which would be worsened
when introducing additional submodules.
2021-03-21 21:37:10 +01:00
WarmUpTill
2a87334d38 Init noMatchDelay to zero. (#148)
A non-zero value might be confusing for users which set up the plugin
for the first time.
2021-03-21 14:44:42 +01:00
WarmUpTill
1a4724ff21 Fix audio tab not supporting mono audio output. (#145) 2021-03-19 20:01:15 +01:00
WarmUpTill
59d8fb5d28 Fix MacOS build. (#146) 2021-03-19 19:43:58 +01:00
WarmUpTill
8823c05aeb Fix scene groups not being selected when using more than one entry on the Random tab. (#143) 2021-03-18 21:22:33 +01:00
WarmUpTill
2d0a52f8d1 Enable use of Scene Groups for Random tab (#141) 2021-03-17 20:00:06 +01:00
WarmUpTill
1273446ce5 Add option to configure default transition delay. (#140) 2021-03-17 18:21:42 +01:00
WarmUpTill
177ca4aea2 CI: Build on Ubuntu 18.04, use newer clang-format. (#139) 2021-03-13 17:02:04 +01:00
WarmUpTill
7526cbe1a3 Add option to check volume of 'inactive' audio sources. (#137) 2021-03-12 18:48:06 +01:00
WarmUpTill
e4bb034303 Add video tab (#131)
This tab will allow switching scenes based on the video output of sources.
2021-03-05 14:08:17 +01:00
WarmUpTill
78e14df620 Add german locale for extended sequences (#135) 2021-03-01 20:25:18 +01:00
WarmUpTill
34f07bfb07 Clean up extended sequence (#134)
* Update original switch widget status if changed in extend edit

* Clean up

* Add more comments

* Clean up unecessary code.

Sleep no longer happens inside the sequence switch check so we don't
need to stop / start the switcher after importing new entries or deleting
existing entries.
2021-02-28 15:38:33 +01:00
WarmUpTill
ee74d39424 Fixes and Minor rework (#132)
* Fix warning in scene trigger log functions.
* Use GetWeakSourceName() when saving scene trigger sources.
* Fix prioFuncsValid().
2021-02-26 19:21:02 +01:00
WarmUpTill
33667a1f23 Fix crash on advancing to unset scene for extended sequence (#130) 2021-02-24 18:53:52 +01:00
WarmUpTill
7947ad2608 Add option to extend scene sequences (#121)
Extending a scene sequence allows for more complex switching setups, but should also simplify some setups.
Sequences like "A -> B -> A -> C", which previously were only possible by creating a copy of A, can now be specified in a single entry.
To extend a sequence either select the sequence you want to modify and click the extend sequence button or simply double click the entry.
2021-02-24 18:19:23 +01:00
WarmUpTill
920c188213 Add scene trigger for starting and stopping the scene switcher (#129) 2021-02-23 21:00:25 +01:00
WarmUpTill
28fbff1adc Allow specifying transition when reading scenes from file. (#128)
The transition can be specified on the second line of the file.
For example:
Scene 1
Slide
2021-02-21 20:17:32 +01:00
WarmUpTill
326617aad7 Fix checkSwitchInfoFromFile ignoring file switch puase (#127) 2021-02-21 20:16:51 +01:00
WarmUpTill
499ba7dd21 Update the UI's status element if the status changed externally (#126) 2021-02-20 18:58:07 +01:00
WarmUpTill
f4902933ab Fix getCurrentScene() returning garbage if scene group has type random (#125) 2021-02-20 18:08:47 +01:00
WarmUpTill
9aa0b31bff Add scene trigger to unmute source (#124) 2021-02-20 18:08:35 +01:00
WarmUpTill
6d5086b971 Add option to select 'current transition' (#123)
* move addSelectionEntry to AdvSceneSwitcher class and allow select entry to be 'selectable'

Can be useful for implementing 'current transition' as an option or just allowing to select 'None' for screen region ignore

* Add option to select 'current transition'
2021-02-19 19:03:38 +01:00
WarmUpTill
f32f47db4b Install qtbase5-private-dev on Linux (#122) 2021-02-13 19:28:24 +01:00
WarmUpTill
74c0cd1736 Adjust sleep log message and comment for sceneChangedDuringWait() (#120) 2021-02-13 19:14:28 +01:00
WarmUpTill
a74a952b1d Fix log messages containing two '[adv-ss]' tags (#118) 2021-02-07 18:41:47 +01:00
WarmUpTill
5bbfef81e0 Improve scene trigger handling (#117) 2021-02-06 18:23:57 +01:00
WarmUpTill
c31d1cd975 Delay setting of default scene transitions (#116) 2021-02-06 18:23:41 +01:00
WarmUpTill
81d91a9139 resovle name conflict (#115) 2021-02-04 07:24:52 +01:00
WarmUpTill
a354daa71d Fix regex matching for window tab (#113)
Regex matches could never match if full-screen or maximized was selected due to only checking for direct matches during these checks.
2021-02-03 20:46:25 +01:00
WarmUpTill
a84a205608 Minor style changes (#114)
* use GetWeakSourceName() where possible

* add getCurrentScene() to scene group

* silence OBS warning log and fix typo in audio switch

* extract showing initial status of widgets to function in generic switch
2021-02-03 20:27:25 +01:00
WarmUpTill
a5f0eb8da8 Add option to automatically start scene switcher on recording / streaming start (#112) 2021-02-03 20:02:07 +01:00
WarmUpTill
35151ea134 Add scene trigger tab (#110) 2021-02-03 19:50:37 +01:00
Kevin Nash
1510a2c2fa Specify scenes to exclude from Region triggers (#111)
Adds an option to exclude a region triggered scene switch if you're
currently in the specified Scene.
2021-02-03 19:49:18 +01:00
WarmUpTill
8e8cb4bf3e use exportWindowTitle on export of settings 2021-01-27 19:05:46 +01:00
WarmUpTill
a480be3ea0 Update installation instructions 2021-01-25 22:15:40 +01:00
WarmUpTill
27ae5107cd Add help messages if tab is empty (#107) 2021-01-24 16:04:40 +01:00
WarmUpTill
69d452f978 allow selection of previous scene for exe,file,region,window and scene group for idle switches (#106) 2021-01-23 23:21:59 +01:00
WarmUpTill
fe9457427f add linger variable instead of sleeping inside sequence match (#105)
This solves issues with the busy loop detection and adds the possibility of other switching methods to delay the scene switch
2021-01-23 20:32:32 +01:00
WarmUpTill
d989c2b570 Add scene groups and rework save and load (#103) 2021-01-23 17:39:35 +01:00
WarmUpTill
1f4679433e ask for backup of settings if a new version detected (#104) 2021-01-23 17:08:17 +01:00
WarmUpTill
b42de8d5c8 fix crash on settings import (#102)
This crash could happen if the scene switcher was currently stuck waiting in a scene sequence causing while the import of new settings took place potentially invalidating the settings of the sequence after wakeup.
2021-01-20 19:01:56 +01:00
WarmUpTill
0950d93828 allow selection of target for auto stop of recoding or streaming 2021-01-18 01:20:56 +01:00
113 changed files with 14737 additions and 2722 deletions

View File

@@ -27,6 +27,7 @@ jobs:
uses: actions/checkout@v2.3.4
with:
path: UI/frontend-plugins/${{ env.PLUGIN_NAME }}
submodules: 'recursive'
- name: Fetch Git Tags
run: |
cd UI/frontend-plugins/${{ env.PLUGIN_NAME }}
@@ -62,7 +63,7 @@ jobs:
echo "add_subdirectory(${{ env.PLUGIN_NAME }})" >> UI/frontend-plugins/CMakeLists.txt
mkdir ./build
cd ./build
cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DDISABLE_PYTHON=ON -DDepsPath="/tmp/obsdeps" -DQTDIR="/tmp/obsdeps" ..
cmake -DBUILD_BROWSER=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DDISABLE_PYTHON=ON -DDepsPath="/tmp/obsdeps" -DQTDIR="/tmp/obsdeps" ..
cd -
- name: Build
shell: bash
@@ -75,8 +76,9 @@ jobs:
if: success()
shell: bash
run: |
curl -L -O https://s3-us-west-2.amazonaws.com/obs-nightly/Packages.pkg
sudo installer -pkg ./Packages.pkg -target /
curl -L -O http://s.sudre.free.fr/Software/files/Packages.dmg
sudo hdiutil attach ./Packages.dmg
sudo installer -pkg /Volumes/Packages\ 1.2.9/Install\ Packages.pkg -target /
- name: Package
if: success()
shell: bash
@@ -102,7 +104,7 @@ jobs:
path: ./nightly/*.pkg
ubuntu64:
name: 'Linux/Ubuntu 64-bit'
runs-on: [ubuntu-latest]
runs-on: [ubuntu-18.04]
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
@@ -113,6 +115,7 @@ jobs:
uses: actions/checkout@v2.3.4
with:
path: UI/frontend-plugins/${{ env.PLUGIN_NAME }}
submodules: 'recursive'
- name: Add plugin to obs cmake
shell: bash
run: echo "add_subdirectory(${{ env.PLUGIN_NAME }})" >> UI/frontend-plugins/CMakeLists.txt
@@ -161,6 +164,7 @@ jobs:
pkg-config \
python3-dev \
qtbase5-dev \
qtbase5-private-dev \
libqt5svg5-dev \
swig \
libxss-dev
@@ -169,7 +173,7 @@ jobs:
run: |
mkdir ./build
cd ./build
cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DWITH_RTMPS=OFF -DBUILD_BROWSER=OFF ..
cmake -DENABLE_PIPEWIRE=OFF -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DWITH_RTMPS=OFF -DBUILD_BROWSER=OFF ..
- name: 'Build'
shell: bash
working-directory: ${{ github.workspace }}/build
@@ -209,6 +213,7 @@ jobs:
uses: actions/checkout@v2.3.4
with:
path: UI/frontend-plugins/${{ env.PLUGIN_NAME}}
submodules: 'recursive'
- name: Add plugin to obs cmake
shell: cmd
run: echo add_subdirectory(${{ env.PLUGIN_NAME }}) >> UI/frontend-plugins/CMakeLists.txt
@@ -270,7 +275,7 @@ jobs:
release:
needs: [macos64, ubuntu64, windows]
name: 'Create Release'
runs-on: [ubuntu-latest]
runs-on: [ubuntu-18.04]
steps:
- name: "Checkout plugin"
uses: actions/checkout@v2.3.4

View File

@@ -8,23 +8,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Install clang format
run: |
# gets us newer clang
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
# 3.8
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
LLVMAPT
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get -qq update
sudo apt-get install -y clang-format-8
sudo apt-get install -y clang-format-10
- name: Check the Formatting
run: |

6
.gitmodules vendored Normal file
View File

@@ -0,0 +1,6 @@
[submodule "deps/asio"]
path = deps/asio
url = https://github.com/chriskohlhoff/asio.git
[submodule "deps/websocketpp"]
path = deps/websocketpp
url = https://github.com/zaphoyd/websocketpp.git

View File

@@ -6,6 +6,8 @@ set -o errexit
set -o pipefail
set -o nounset
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Runs the Clang Formatter in parallel on the code base.
# Return codes:
# - 1 there are files to be formatted
@@ -19,13 +21,15 @@ if [[ $OS = "Linux" || $OS = "Darwin" ]] ; then
fi
# Discover clang-format
if type clang-format-8 2> /dev/null ; then
if type clang-format-10 2> /dev/null ; then
CLANG_FORMAT=clang-format-10
elif type clang-format-8 2> /dev/null ; then
CLANG_FORMAT=clang-format-8
else
CLANG_FORMAT=clang-format
fi
find .. -type d \( -path ./deps \
-o -path ./cmake \
-o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
find $SCRIPTPATH/.. -type d \( -path $SCRIPTPATH/../deps \
-o -path $SCRIPTPATH/../cmake \
-o -path $SCRIPTPATH/../build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
| xargs -L100 -P${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none

View File

@@ -1,31 +1,42 @@
Note that you will have to use OBS version 25 or newer!
Note that you will have to use OBS version 26.1 or newer!
--- WINDOWS ---
--- Windows ---
Recommended: Run the provided installer. (You might have to click 'More info' and select 'Run anyway' if it is blocked by Windows)
Alternatively manually copy the 'obs-plugins' and 'data' folders in the respective OBS Studio installation directory.
It is usually located at 'C:\Program Files (x86)\obs-studio\'.
Remember to install the Visual C++ Redistributable for Visual Studio 2019, if you have not done so already. (See plugin overview page)
--- MAC OS ---
Recommended: Run the provided installer. (You might have to right click and select 'open' if it is blocked)
--- macOS ---
Recommended: Run the provided installer. (You might have to right-click or control-click and select 'open' if it is blocked)
Alternatively extract the *so file and data folder and either ...
... right click the OBS app inside your Applications folder and choose 'Show Package Contents'.
... right-click the OBS app inside your Applications folder and choose 'Show Package Contents'.
Copy the advanced-scene-switcher.so file to 'Contents/Plugins' and the 'data' folder to 'Contents/Resources'.
... or copy the advanced-scene-switcher.so file to Library/Application Support/obs-studio/plugins/advanced-scene-switcher/bin/ .
And the 'data' folder to 'Library/Application Support/obs-studio/plugins/advanced-scene-switcher/'.
--- Linux ---
Copy the advanced-scene-switcher.so file and data folder into the OBS Studio plugin folder.
The location of this folder can vary so you might have to look around a bit.
Copy the advanced-scene-switcher.so file and into the OBS Studio plugin folder.
The location of this folder can vary, so you might have to look around a bit.
Examples are ...
/usr/lib/obs-plugins/
/usr/lib/x86_64-linux-gnu/obs-plugins/
/usr/share/obs/obs-plugins/
~/.config/obs-studio/plugins/advanced-scene-switcher/bin/64bit/
~/.local/share/flatpak/app/com.obsproject.Studio/x86_64/stable/active/files/lib/obs-plugins/
/var/lib/flatpak/app/com.obsproject.Studio/x86_64/stable/active/files/lib/obs-plugins/
Unfortunately the expected location of the locale, which can be found in the data folder, can vary also.
The data folder usually should be copied to:
~/.config/obs-studio/plugins/advanced-scene-switcher/
If this does not work you can try to copy the "locale" folder found inside the data folder to:
/usr/share/obs/obs-plugins/advanced-scene-switcher/locale
~/.local/share/flatpak/app/com.obsproject.Studio/x86_64/stable/active/files/share/obs/obs-plugins/advanced-scene-switcher/locale
/var/lib/flatpak/app/com.obsproject.Studio/x86_64/stable/active/files/share/obs/obs-plugins/advanced-scene-switcher/locale
In doubt please check where other "en-US.ini" files are located on your system.

View File

@@ -1,12 +1,20 @@
cmake_minimum_required(VERSION 3.5)
project(advanced-scene-switcher)
add_definitions(-DASIO_STANDALONE)
# generate version info
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp" @ONLY)
if(WIN32)
get_filename_component(ISS_PLUGIN_FILES_DIR "${CMAKE_BINARY_DIR}\\..\\package" ABSOLUTE)
file(TO_NATIVE_PATH "${ISS_PLUGIN_FILES_DIR}" ISS_PLUGIN_FILES_DIR)
get_filename_component(ISS_MSVC_REDIST_HELPER_DIR "${CMAKE_PACKAGE_PREFIX}\\.." ABSOLUTE)
file(TO_NATIVE_PATH "${ISS_MSVC_REDIST_HELPER_DIR}" ISS_MSVC_REDIST_HELPER_DIR)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/CI/windows/setup.iss.in" "${CMAKE_CURRENT_BINARY_DIR}/CI/windows/setup.iss" @ONLY)
endif()
if(WIN32)
get_filename_component(ISS_PLUGIN_FILES_DIR "${CMAKE_BINARY_DIR}\\..\\package" ABSOLUTE)
@@ -45,18 +53,24 @@ if(UNIX AND NOT APPLE)
include_directories(${X11_INCLUDE_DIR})
endif()
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/websocketpp"
)
set(advanced-scene-switcher_HEADERS
${advanced-scene-switcher_HEADERS}
src/headers/advanced-scene-switcher.hpp
src/headers/switcher-data-structs.hpp
src/headers/utility.hpp
src/headers/curl-helper.hpp
src/headers/volume-control.hpp
src/headers/scene-group.hpp
src/headers/scene-trigger.hpp
src/headers/switch-audio.hpp
src/headers/switch-executable.hpp
src/headers/switch-file.hpp
src/headers/switch-idle.hpp
src/headers/switch-media.hpp
src/headers/switch-network.hpp
src/headers/switch-pause.hpp
src/headers/switch-random.hpp
src/headers/switch-screen-region.hpp
@@ -64,7 +78,36 @@ set(advanced-scene-switcher_HEADERS
src/headers/switch-transitions.hpp
src/headers/switch-window.hpp
src/headers/switch-sequence.hpp
src/headers/switch-video.hpp
src/headers/switch-generic.hpp
src/headers/macro-action-edit.hpp
src/headers/macro-action-audio.hpp
src/headers/macro-action-recording.hpp
src/headers/macro-action-replay-buffer.hpp
src/headers/macro-action-run.hpp
src/headers/macro-action-streaming.hpp
src/headers/macro-action-switch-scene.hpp
src/headers/macro-action-wait.hpp
src/headers/macro-condition-edit.hpp
src/headers/macro-condition-audio.hpp
src/headers/macro-condition-file.hpp
src/headers/macro-condition-idle.hpp
src/headers/macro-condition-media.hpp
src/headers/macro-condition-plugin-state.hpp
src/headers/macro-condition-process.hpp
src/headers/macro-condition-recording.hpp
src/headers/macro-condition-region.hpp
src/headers/macro-condition-scene.hpp
src/headers/macro-condition-streaming.hpp
src/headers/macro-condition-video.hpp
src/headers/macro-condition-window.hpp
src/headers/macro.hpp
src/headers/curl-helper.hpp
src/headers/screenshot-helper.hpp
src/headers/name-dialog.hpp
src/headers/duration-control.hpp
src/headers/section.hpp
src/headers/volume-control.hpp
src/headers/version.h
)
@@ -73,6 +116,8 @@ set(advanced-scene-switcher_SOURCES
src/advanced-scene-switcher.cpp
src/advanced-scene-switcher-module.c
src/switcher-data-structs.cpp
src/scene-group.cpp
src/scene-trigger.cpp
src/switch-transitions.cpp
src/switch-screen-region.cpp
src/switch-priority.cpp
@@ -82,14 +127,43 @@ set(advanced-scene-switcher_SOURCES
src/switch-file.cpp
src/switch-window.cpp
src/switch-media.cpp
src/switch-network.cpp
src/hotkey.cpp
src/general.cpp
src/switch-pause.cpp
src/switch-random.cpp
src/switch-time.cpp
src/switch-audio.cpp
src/switch-video.cpp
src/switch-generic.cpp
src/macro-action-edit.cpp
src/macro-action-audio.cpp
src/macro-action-recording.cpp
src/macro-action-replay-buffer.cpp
src/macro-action-run.cpp
src/macro-action-streaming.cpp
src/macro-action-switch-scene.cpp
src/macro-action-wait.cpp
src/macro-condition-edit.cpp
src/macro-condition-audio.cpp
src/macro-condition-file.cpp
src/macro-condition-idle.cpp
src/macro-condition-media.cpp
src/macro-condition-plugin-state.cpp
src/macro-condition-process.cpp
src/macro-condition-recording.cpp
src/macro-condition-region.cpp
src/macro-condition-scene.cpp
src/macro-condition-streaming.cpp
src/macro-condition-video.cpp
src/macro-condition-window.cpp
src/macro.cpp
src/macro-tab.cpp
src/curl-helper.cpp
src/screenshot-helper.cpp
src/name-dialog.cpp
src/duration-control.cpp
src/section.cpp
src/volume-control.cpp
src/version.cpp
)
@@ -100,6 +174,8 @@ set(advanced-scene-switcher_UI
)
if(WIN32)
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
set(advanced-scene-switcher_PLATFORM_SOURCES
src/win/advanced-scene-switcher-win.cpp)
elseif(APPLE)

View File

@@ -1,7 +1,7 @@
# SceneSwitcher
An automated scene switcher for OBS Studio
More information can be found on https://obsproject.com/forum/resources/automatic-scene-switching.395/
More information can be found on https://obsproject.com/forum/resources/automatic-scene-switching.395/ and see https://github.com/WarmUpTill/SceneSwitcher/blob/master/CI/release/README.txt for installing releases.
## Compiling in tree (recommended)
Add the "SceneSwitcher" source directory to your obs-studio source directory under obs-studio/UI/frontend-plugins/:

View File

@@ -6,19 +6,19 @@ AdvSceneSwitcher.generalTab.title="Allgemein"
AdvSceneSwitcher.generalTab.status="Status"
AdvSceneSwitcher.generalTab.status.hotkeytips="Hotkeys können in den OBS Einstellungen konfiguriert werden"
AdvSceneSwitcher.generalTab.status.currentStatus="Erweiterter Automatischer Szenenwechsler ist:"
AdvSceneSwitcher.generalTab.status.onStartup="Beim Start:"
AdvSceneSwitcher.generalTab.status.onStartup="Beim Start von OBS:"
AdvSceneSwitcher.generalTab.status.onStartup.asLastRun="Aktiviere den Szenenwechsler wenn er aktiv war"
AdvSceneSwitcher.generalTab.status.onStartup.alwaysStart="Aktiviere den Szenenwechsler"
AdvSceneSwitcher.generalTab.status.onStartup.doNotStart="Aktiviere den Szenenwechsler nicht"
AdvSceneSwitcher.generalTab.status.start="Start"
AdvSceneSwitcher.generalTab.status.stop="Stop"
AdvSceneSwitcher.generalTab.status.autoStart="Starte auotmatischen den Szenenwechsler beim:"
AdvSceneSwitcher.generalTab.status.autoStart.never="Niemals"
AdvSceneSwitcher.generalTab.status.autoStart.recording="Aufnehmen"
AdvSceneSwitcher.generalTab.status.autoStart.streaming="Streamen"
AdvSceneSwitcher.generalTab.status.autoStart.recordingAndStreaming="Aufnehmen oder Streamen"
AdvSceneSwitcher.generalTab.status.checkInterval="Teste Bedingungen alle"
AdvSceneSwitcher.generalTab.generalBehavior="Allgemeines Verhalten"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recording="Aufnehmen"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.streaming="Streamen"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recordingAndStreaming="Aufnehmen und Streamen"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart1="Starte"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart2=" auf Szene"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet="Wenn keine Bedingung erfüllt ist für "
AdvSceneSwitcher.generalTab.generalBehavior.onNoMetDelayTooltip="Kann nur so genau sein wie das eingestellte Interval zum Testen der Bedingungen."
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.dontSwitch="Nicht wechseln"
@@ -27,7 +27,7 @@ AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo="Wechsle zu:"
AdvSceneSwitcher.generalTab.generalBehavior.cooldown="Nach einem automatisierten Szenenwechsel wechsle nicht mehr für"
AdvSceneSwitcher.generalTab.generalBehavior.cooldownHint="In diesem Zeitraum werden potentielle erfüllte Bedingungen ignoriert!"
AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging="Ausführliches Logging"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStop="Stoppe Streamen/Aufnehmen auf Szene"
AdvSceneSwitcher.generalTab.generalBehavior.saveWindowGeo="Fensterposition und -größe speichern"
AdvSceneSwitcher.generalTab.generalBehavior.disableUIHints="Deaktiviere UI Tipps"
AdvSceneSwitcher.generalTab.priority="Priorität"
AdvSceneSwitcher.generalTab.priority.description="Szenenwechselmethoden sortiert nach Priorität"
@@ -50,15 +50,22 @@ AdvSceneSwitcher.generalTab.priority.windowTitle="Fenstername"
AdvSceneSwitcher.generalTab.priority.media="Medien"
AdvSceneSwitcher.generalTab.priority.time="Zeit"
AdvSceneSwitcher.generalTab.priority.audio="Audio"
AdvSceneSwitcher.generalTab.priority.video="Video"
; Transition Tab
AdvSceneSwitcher.transitionTab.title="Szenenübergänge"
AdvSceneSwitcher.transitionTab.transitionOverride="Szenenübergänge, die im Szenenwechsler konfiguriert werden, haben Vorrang vor Übergangsüberschreibung"
AdvSceneSwitcher.transitionTab.setTransitionBy="Beim Ändern des Szenenübergangs:"
AdvSceneSwitcher.transitionTab.transitionOverride="Verwende Übergangsüberschreibungen"
AdvSceneSwitcher.transitionTab.adjustActiveTransitionType="Wechsle den aktiven Szenenübergangtyp"
AdvSceneSwitcher.transitionTab.transitionBehaviorSelectionError="Mindestens eine Option muss aktiv sein:\n\n - Verwende Übergangsüberschreibungen\n\n - Wechsle den aktiven Szenenübergangtyp"
AdvSceneSwitcher.transitionTab.transitionForAToB="Szenenübergänge für automatisierte Szenenwechsel von Szene A zu Szene B"
AdvSceneSwitcher.transitionTab.transitionForAToB.description="<html><head/><body><p>Diese Einstellungen beeinflussen <span style=\"font-style:italic;\">nur</span> vom Szenenwechsler ausgelöste Szenenübergänge - Siehe <a href=\"https://obsproject.com/forum/resources/transition-table.1174/\"><span style=\" text-decoration: underline; color:#268bd2;\">Transition Table</span></a> um auch manuelle Szenenübergänge zu konfigurieren.<br/>Einstellungen auf diesem Tab haben Vorrang vor denen welche auf den übrigen Tabs konfiguriert wurden.</p></body></html>"
AdvSceneSwitcher.transitionTab.transitionsHelp="<html><head/><body><p>Diese Einstellungen beeinflussen <span style=\"font-style:italic;\">nur</span> vom Szenenwechsler ausgelöste Szenenübergänge - Siehe <a href=\"https://obsproject.com/forum/resources/transition-table.1174/\"><span style=\" text-decoration: underline; color:#268bd2;\">Transition Table</span></a> um auch manuelle Szenenübergänge zu konfigurieren.<br/>Einstellungen auf diesem Tab haben Vorrang, vor denen welche auf den übrigen Tabs konfiguriert wurden.<br/><br/>Klicke auf das Plus Symbol, um einen neuen Eintrag hinzuzufügen.</p></body></html>"
AdvSceneSwitcher.transitionTab.defaultTransition="Ändere den Szenenübergang wenn eine Szene aktiv ist"
AdvSceneSwitcher.transitionTab.entry="Wechsle von {{scenes}} zu {{scenes2}} mit {{transitions}}"
AdvSceneSwitcher.transitionTab.entry="Wechsle von {{scenes}} zu {{scenes2}} mit {{transitions}} mit einer Dauer von {{duration}}"
AdvSceneSwitcher.transitionTab.defaultTransitionEntry="Wenn {{scenes}} aktiv ist ändere den Szenenübergang zu {{transitions}}"
AdvSceneSwitcher.transitionTab.defaultTransitionsHelp="Klicke auf das Plus Symbol, um einen neuen Eintrag hinzuzufügen."
AdvSceneSwitcher.transitionTab.defaultTransition.delay="Wechsle Szenenübergang {{defTransitionDelay}} nach Szenenwechsel."
AdvSceneSwitcher.transitionTab.defaultTransition.delay.help="Diese Verzögerung dient dazu Szenenwechsel zu unterbrechen.\nDies kann passieren, wenn der Szenenübergangtyp gewechselt wird während ein Szenenübergang grade noch im Gang ist."
; Pause Scenes Tab
AdvSceneSwitcher.pauseTab.title="Pause"
@@ -69,6 +76,7 @@ AdvSceneSwitcher.pauseTab.pauseTypeScene="Szene aktiv ist"
AdvSceneSwitcher.pauseTab.pauseTypeWindow="Fenster im Fokus ist"
AdvSceneSwitcher.pauseTab.pauseTargetAll="alle"
AdvSceneSwitcher.pauseTab.pauseEntry="Pausiere {{pauseTargets}} Überprüfungen wenn {{scenes}} {{windows}} {{pauseTypes}}"
AdvSceneSwitcher.pauseTab.help="Auf diesem Tab können einzelne Szenenwechselmethoden pausiert werden, wenn eine Szene aktiv oder ein Fenster im Fokus ist.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Window Title Tab
AdvSceneSwitcher.windowTitleTab.title="Fenstername"
@@ -79,19 +87,24 @@ AdvSceneSwitcher.windowTitleTab.fullscreen="wenn Vollbild"
AdvSceneSwitcher.windowTitleTab.maximized="wenn maximiert"
AdvSceneSwitcher.windowTitleTab.focused="wenn fokussiert"
AdvSceneSwitcher.windowTitleTab.entry="{{windows}} {{scenes}} {{transitions}} {{fullscreen}} {{maximized}} {{focused}}"
AdvSceneSwitcher.windowTitleTab.windowsHelp="Wechsle Szenen basiert auf dem Fensternamen eines laufenden Prozesses.\nFolgende zusätzliche Bedingungen können ausgewählt werden:\nDas Fenster ist im Vollbildmodus\nDas Fenster ist maximiert\nDas Fenster ist fokussiert\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
AdvSceneSwitcher.windowTitleTab.ignoreWindowsHelp="Ist ein Fenstername ignoriert so verhält sich der Szenenwechsler als ob das vorhergehende Fenster immer noch fokussiert ist.\nDies kann in Situationen nützlich sein, in den oft zwischen Fenster gewechselt wird, dies aber nicht immer einen Szenenwechsel auslösen soll.\n\nWähle oben ein Fenster aus oder gib einen Fensternamen ein und klicke auf das Plus Symbol um es zur Liste hinzuzufügen."
; Executable Tab
AdvSceneSwitcher.executableTab.title="Prozess"
AdvSceneSwitcher.executableTab.implemented="Implementiert von dasOven"
AdvSceneSwitcher.executableTab.requiresFocus="nur wenn dieser fokussiert ist"
AdvSceneSwitcher.executableTab.entry="Wenn {{processes}} läuft wechsle zu {{scenes}} mit {{transitions}} {{requiresFocus}}"
AdvSceneSwitcher.executableTab.help="Dieser Tab erlaubt es Szenen zu wechseln, wenn bestimmte Prozesse laufen.\nDas kann nützlich sein, wenn sich der Name eines Fensters ändern kann oder dieser nicht bekannt ist.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Screen Region Tab
AdvSceneSwitcher.screenRegionTab.title="Bildschrimbereich"
AdvSceneSwitcher.screenRegionTab.currentPosition="Mauszeiger ist bei:"
AdvSceneSwitcher.screenRegionTab.showGuideFrames="Hilfsrahmen einblenden"
AdvSceneSwitcher.screenRegionTab.hideGuideFrames="Hilfsrahmen ausblenden"
AdvSceneSwitcher.screenRegionTab.entry="Wenn der Mauszeiger in {{minX}} {{minY}} x {{maxX}} {{maxY}} ist wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.screenRegionTab.excludeScenes.None="Keine Auswahl"
AdvSceneSwitcher.screenRegionTab.entry="Wenn der Mauszeiger in {{minX}} {{minY}} x {{maxX}} {{maxY}} ist wechsle zu {{scenes}} mit {{transitions}} außer wenn auf {{excludeScenes}}"
AdvSceneSwitcher.screenRegionTab.help="Dieser Tab ermöglicht es basierend auf der Position des Mauszeigers Szenen zu wechseln.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Media Tab
AdvSceneSwitcher.mediaTab.title="Medien"
@@ -112,6 +125,7 @@ AdvSceneSwitcher.mediaTab.timeRestriction.longer="Dauer länger"
AdvSceneSwitcher.mediaTab.timeRestriction.remainShorter="übrige Zeit kürzer"
AdvSceneSwitcher.mediaTab.timeRestriction.remainLonger="übrige Zeit länger"
AdvSceneSwitcher.mediaTab.entry="Wenn {{mediaSources}} im Status {{states}} ist und{{timeRestrictions}} {{time}} ist wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.mediaTab.help="Dieser Tab ermöglicht es basieren auf dem Status von Medienquellen Szenen zu wechseln.\nZum Beispiel kann automatisch zur vorhergehenden Szene gewechselt werden, sobald sich eine Medienquelle im Status Beendet befindet.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; File Tab
AdvSceneSwitcher.fileTab.title="Datei Inhalt"
@@ -136,11 +150,13 @@ AdvSceneSwitcher.fileTab.checkfileContent="nur wenn sich der Inhalt geänder hat
AdvSceneSwitcher.fileTab.entry="Wechsle zu {{scenes}} mit {{transitions}} wenn der Inhalt von {{fileType}} {{filePath}} {{browseButton}} passt zu:"
AdvSceneSwitcher.fileTab.entry2="{{matchText}}"
AdvSceneSwitcher.fileTab.entry3="{{useRegex}} {{checkModificationDate}} {{checkFileContent}}"
AdvSceneSwitcher.fileTab.help="Dieser Tab erlaubt es Szenen zu wechseln basierend auf dem Inhalt von lokalen oder remote Dateien.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Random Tab
AdvSceneSwitcher.randomTab.title="Zufall"
AdvSceneSwitcher.randomTab.randomDisabledWarning="Funktionalität deaktiviert - Um diese zu aktivieren wähle \"Wenn keine Bedingung erfüllt ist wechsle zu einer Szene auf dem Zufall-Tab\" auf dem Allgemein-Tab aus"
AdvSceneSwitcher.randomTab.entry="Wenn keine Bedingung erfüllt ist wechsle zu {{scenes}} mit {{transitions}} für {{delay}}"
AdvSceneSwitcher.randomTab.help="Der Szenenwechsler wählt zufällig einen Eintrag auf diesem Tab aus, zu dem er für die angegebene Zeit wechseln wird.\nDer gleiche Eintrag wird nicht zweimal nacheinander ausgewählt werden.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Time Tab
AdvSceneSwitcher.timeTab.title="Zeit"
@@ -155,15 +171,12 @@ AdvSceneSwitcher.timeTab.sundays="Sonntags"
AdvSceneSwitcher.timeTab.afterstart="Nach Streamen-/Aufnehmenstart"
AdvSceneSwitcher.timeTab.afterstart.tip="Hier wird die Zeit relativ zum Starten des Streamen/Aufnehmen gemessen"
AdvSceneSwitcher.timeTab.entry="{{triggers}} um {{time}} wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.timeTab.help="Dieser Tab ermöglicht es Szenen basierend auf der aktuellen Uhrzeit zu wechseln.\n\nDer Szenenwechsler versucht den Szenenwechsel nur zur eingestellten Uhrzeit auszulösen.\nBeachte, dass die Prioritätseinstellungen auf dem Allgemein Tab entsprechend konfiguriert sind, sodass keine andere Szenenwechselmethode hier konfiguriert Einstellungen zur gegebenen Uhrzeit übertrifft.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Idle Tab
AdvSceneSwitcher.idleTab.title="Inaktivitätserkennung"
AdvSceneSwitcher.idleTab.enable="Aktiviere Inaktivitätserkennung"
AdvSceneSwitcher.idleTab.condition1="Nach "
AdvSceneSwitcher.idleTab.condition2="ohne Keyboard- oder Mauseingaben"
AdvSceneSwitcher.idleTab.switchToScene="wechsle zu Szene"
AdvSceneSwitcher.idleTab.usingTransition1="mit"
AdvSceneSwitcher.idleTab.usingTransition2=" "
AdvSceneSwitcher.idleTab.idleswitch="After {{duration}} ohne Keyboard- oder Mauseingaben wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.idleTab.dontSwitchIfFocus1="Wechsle nicht wenn"
AdvSceneSwitcher.idleTab.dontSwitchIfFocus2="im Fokus ist"
@@ -179,29 +192,117 @@ AdvSceneSwitcher.sceneSequenceTab.loadSuccess="Laden der Einstellungen war erfol
AdvSceneSwitcher.sceneSequenceTab.fileType="Text Dateien (*.txt)"
AdvSceneSwitcher.sceneSequenceTab.interruptible="kann unterbrochen werden"
AdvSceneSwitcher.sceneSequenceTab.interruptibleHint="Andere Szenenwechselmethoden können diese Sequenz unterbrechen"
AdvSceneSwitcher.sceneSequenceTab.entry="Wenn {{startScenes}} aktiv ist wechsle zu {{scenes}} nach {{delay}} {{delayUnits}} mit {{transitions}} {{interruptible}}"
AdvSceneSwitcher.sceneSequenceTab.extendEdit="Szenenfolge erweitern"
AdvSceneSwitcher.sceneSequenceTab.extendEntry="Nach {{delay}} wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.sceneSequenceTab.entry="Wenn {{startScenes}} aktiv ist wechsle zu {{scenes}} nach {{delay}} mit {{transitions}} {{interruptible}}"
AdvSceneSwitcher.sceneSequenceTab.help="Dieser Tab ermöglicht es automatisiert zu einer anderen Szene zu wechseln, nachdem eine Szene für die konfigurierte Zeit aktiv war.\nZum Beispiel kann so automatisch zwischen zwei Szenen hin und her gewechselt werden.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Audio Tab
AdvSceneSwitcher.audioTab.title="Audio"
AdvSceneSwitcher.audioTab.condition.above="über"
AdvSceneSwitcher.audioTab.condition.below="unter"
AdvSceneSwitcher.audioTab.entry="Wenn die Lautstärke von {{audioSources}} {{condition}} {{volumeWidget}} ist für {{duration}} wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.audioTab.ignoreInactiveSource="außer Audio Quelle ist inaktiv"
AdvSceneSwitcher.audioTab.entry="Wenn die Lautstärke von {{audioSources}} {{condition}} {{volumeWidget}} ist für {{duration}} Sekunden wechsle zu {{scenes}} mit {{transitions}} {{ignoreInactiveSource}}"
AdvSceneSwitcher.audioTab.multiMatchfallbackCondition="Wenn mehrere Einträge zutreffen ..."
AdvSceneSwitcher.audioTab.multiMatchfallback="... für {{duration}} wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.audioTab.multiMatchfallback="... für {{duration}} Sekunden wechsle zu {{scenes}} mit {{transitions}}"
AdvSceneSwitcher.audioTab.help="Dieser Tab ermöglicht es basierend auf der Lautstärke von Audioquellen Szenen zu wechseln.\nSo kann zum Beispiel automatisch zu einer Szene gewechselt werden, wenn die Lautstärke eines Mikrofons eine konfigurierte Schwelle überschreitet.\n\nKlicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen."
; Video Tab
AdvSceneSwitcher.videoTab.title="Video"
AdvSceneSwitcher.videoTab.getScreenshot="Screenshot für ausgewählten Eintrag erstellen"
AdvSceneSwitcher.videoTab.getScreenshotHelp="Erstellt einen Screenshot für die Video Quelle des ausgewählten Eintrag und setzt diesen als Ziel Bild"
AdvSceneSwitcher.videoTab.condition.match="genau übereinstimmt mit"
AdvSceneSwitcher.videoTab.condition.match.tooltip="Eine genaue Übereinstimmung setzt voraus, dass sowohl Zielquelle als auch das Bild die gleiche Auflösung besitzen.\nZusätzlich muss jeder einzelne Pixel zwischen beiden Bildquellen übereinstimmen weshalb Bildformate, welche das Bild komprimieren (z. B. .JPG) nicht zu empfehlen sind."
AdvSceneSwitcher.videoTab.condition.differ="nicht übereinstimmt mit"
AdvSceneSwitcher.videoTab.condition.hasNotChanged="sich nicht verändert"
AdvSceneSwitcher.videoTab.condition.hasNotChanged="sich verändert"
AdvSceneSwitcher.videoTab.ignoreInactiveSource="außer Video Quelle ist inaktiv"
AdvSceneSwitcher.videoTab.entry="Wenn {{videoSources}} {{condition}} {{filePath}} {{browseButton}} für {{duration}} wechsle zu {{scenes}} mit {{transitions}} {{ignoreInactiveSource}}"
AdvSceneSwitcher.videoTab.help="<html><head/><body><p>Dieser Tab ermöglicht es basierend auf der Videoausgabe von Quellen scenen zu wechseln.<br/>Für eine noch bessere Implementierung dieser Funktionalität siehe <a href=\"https://obsproject.com/forum/resources/pixel-match-switcher.1202/\"><span style=\" text-decoration: underline; color:#268bd2;\">Pixel Match Switcher</span></a>.<br/><br/>Klicke auf das markierte Plus Symbol, um einen neuen Eintrag hinzuzufügen..</p></body></html>"
; Network Tab
AdvSceneSwitcher.networkTab.title="Netzwerk"
AdvSceneSwitcher.networkTab.warning="Die Verwendung des Servers außerhalb eines lokalen Netzwerks kann dazu führen, dass die aktive Szene von dritten Personen ausgelesen werden kann."
AdvSceneSwitcher.networkTab.Disabledwarning="Diese Funktionalität musste unter macOS leider aufgrund von Bibliotheksinkompatibilitäten mit dem obs-websocket plugin deaktiviert werden."
AdvSceneSwitcher.networkTab.server="Server starten (Sendet Szenenwechselnachrichten zu allen verbundenen Clients)"
AdvSceneSwitcher.networkTab.server.port="Port"
AdvSceneSwitcher.networkTab.server.lockToIPv4="Nur IPv4 verwenden (deaktiviert IPv6)"
AdvSceneSwitcher.networkTab.server.restrictSendToAutomatedSwitches="Sende nur Szenenwechselnachrichten für automatisierte Szenenwechsel"
AdvSceneSwitcher.networkTab.startFailed.message="Der WebSocket-Server konnte nicht gestartet werden, mögliche Gründe:\n - Der TCP-Port %1 wird möglicherweise gerade von einem anderen Programm verwendet. Versuchen Sie einen anderen Port in den Websocket-Servereinstellungen zu setzen oder alle Programme zu beenden, die den Port möglicherweise verwenden.\n - Fehler: %2"
AdvSceneSwitcher.networkTab.server.status.currentStatus="Aktueller Status"
AdvSceneSwitcher.networkTab.server.status.notRunning="Nicht gestartet"
AdvSceneSwitcher.networkTab.server.status.starting="Startet"
AdvSceneSwitcher.networkTab.server.status.running="Server läuft"
AdvSceneSwitcher.networkTab.server.restart="Server neu starten"
AdvSceneSwitcher.networkTab.client="Client starten (Empfängt Szenenwechselnachrichten )"
AdvSceneSwitcher.networkTab.client.address="Hostname oder IP-Adresse"
AdvSceneSwitcher.networkTab.client.port="Port"
AdvSceneSwitcher.networkTab.client.status.currentStatus="Aktueller status"
AdvSceneSwitcher.networkTab.client.status.disconnected="Verbindung getrennt"
AdvSceneSwitcher.networkTab.client.status.connecting="Verbinde"
AdvSceneSwitcher.networkTab.client.status.connected="Verbunden"
AdvSceneSwitcher.networkTab.client.reconnect="Erneutes Verbinden erzwingen"
; Scene Group Tab
AdvSceneSwitcher.sceneGroupTab.title="Szenengruppe"
AdvSceneSwitcher.sceneGroupTab.list="Szenengruppen"
AdvSceneSwitcher.sceneGroupTab.edit="Szenengruppe bearbeiten"
AdvSceneSwitcher.sceneGroupTab.edit.name="Name:"
AdvSceneSwitcher.sceneGroupTab.edit.type="Typ: {{type}}"
AdvSceneSwitcher.sceneGroupTab.type.count="Anzahl"
AdvSceneSwitcher.sceneGroupTab.type.time="Zeit"
AdvSceneSwitcher.sceneGroupTab.type.random="Zufall"
AdvSceneSwitcher.sceneGroupTab.edit.count="Schreite zur nächsten Szene in dieser Gruppe fort nach {{count}} Szenewechseln"
AdvSceneSwitcher.sceneGroupTab.edit.time="Schreite zur nächsten Szene in dieser Gruppe fort nach {{time}}"
AdvSceneSwitcher.sceneGroupTab.edit.random="Wähle eine zufällig Szene in der Liste aus"
AdvSceneSwitcher.sceneGroupTab.edit.repeat="Beginne von vorne wenn Ende der Szenenliste erreicht ist"
AdvSceneSwitcher.sceneGroupTab.edit.addScene="Szene hinzufügen"
AdvSceneSwitcher.sceneGroupTab.add="Szenengruppe hinzufügen"
AdvSceneSwitcher.sceneGroupTab.defaultname="Szenengruppe %1"
AdvSceneSwitcher.sceneGroupTab.exists="Szenengruppen- oder Szenenname existiert bereits"
AdvSceneSwitcher.sceneGroupTab.help="Szenengruppen können, genau wie reguläre Szenen, als Ziel eines Szenenwechsler Eintrags ausgewählt werden.\n\nSzenengruppen bestehen aus einer Liste von Szenen.\nDie aktive Szene der Szenengruppe schreitet abhängig von den konfigurierten Einstellungen durch die Liste der zugewiesenen Szenen fort.\n\nMögliche Einstellungen zum Fortschreiten der aktiven Szene sind:\nAnzahl der Szenenwechsel.\nZeit seit dem letzten Szenenwechsel in der Szenengruppe.\nOder zufällig.\n\nSo kann zum Beispiel eine Szenengruppe welche die folgenden Szenen enthält ...\nSzene 1\nSzene 2\nSzene 3 \n... beim erstem Mal zu \"Szene 1\" wechseln.\nBeim zweiten Mal zu \"Szene 2\".\nDie restlichem Male wechselt die Szenengruppe zu \"Szene 3\".\n\nKlicke auf das markierte Plus Symbol, um eine neuen Szenengruppe hinzuzufügen."
AdvSceneSwitcher.sceneGroupTab.scenes.help="Wähle die Szenengruppe, die du bearbeiten möchtest, auf der linken Seite aus.\n\nWähle oben eine Szene aus, die du zur Szenengruppe hinzufügen möchtest, und klicke das Plus Symbol.\n\nDie gleiche Szene kann mehrfach in derselben Szenengruppe auftauchen."
; Scene Trigger Tab
AdvSceneSwitcher.sceneTriggerTab.title="Szenen Trigger"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.none="--Trigger auswählen--"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneActive="aktiv ist"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneInactive="nicht aktiv ist"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneLeave="verlassen wird"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.none="--Aktion auswählen--"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startRecording="Aufnahme starten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.pauseRecording="Aufnahme pausieren"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unpauseRecording="Aufnahme fortsetzen"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopRecording="Aufnahme stoppen"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopStreaming="Streamen stoppen"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startStreaming="Streamen starten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startReplayBuffer="Replay Buffer starten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopReplayBuffer="Replay Buffer stoppen"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.muteSource="Audio Quelle stumm schalten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unmuteSource="Audio Quelle aktiv schalten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startSwitcher="Szenenwechsler starten"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopSwitcher="Szenenwechsler stoppen"
AdvSceneSwitcher.sceneTriggerTab.entry="Wenn {{scenes}} {{triggers}} {{actions}} {{audioSources}} nach {{duration}} "
AdvSceneSwitcher.sceneTriggerTab.help="Dieser Tab ermöglicht es automatisiert Handlungen, wie etwa das Stoppen von einer Aufnahme oder des Streamens, bei einem Szenenwechsel auszuführen."
; Hotkey
AdvSceneSwitcher.hotkey.startSwitcherHotkey="Starte den Erweiteren Szenenwechsler"
AdvSceneSwitcher.hotkey.stopSwitcherHotkey="Stoppe den Erweiteren Szenenwechsler"
AdvSceneSwitcher.hotkey.startStopToggleSwitcherHotkey="Starte/Stoppe den Erweiteren Szenenwechsler"
AdvSceneSwitcher.askBackup="Neue Version des Erweiterten Automatischen Szenenwechslers wurde erkannt.\nSoll ein Backup der alten Einstellungen angelegt werden?"
AdvSceneSwitcher.close="Schließen"
AdvSceneSwitcher.browse="Öffnen"
AdvSceneSwitcher.selectScene="--Szene auswählen--"
AdvSceneSwitcher.selectPreviousScene="Vorhergehende Szene"
AdvSceneSwitcher.currentTransition="Aktueller Szenenübergang"
AdvSceneSwitcher.selectTransition="--Szenenübergang auswählen--"
AdvSceneSwitcher.selectWindow="--Fenster auswählen--"
AdvSceneSwitcher.selectAudioSource="--Audio Quelle auswählen--"
AdvSceneSwitcher.selectVideoSource="--Video Quelle auswählen--"
AdvSceneSwitcher.selectMediaSource="--Medien Quelle auswählen--"
AdvSceneSwitcher.selectProcess="--Prozess auswählen--"
AdvSceneSwitcher.enterPath="--Pfad eingeben--"

View File

@@ -6,19 +6,19 @@ AdvSceneSwitcher.generalTab.title="General"
AdvSceneSwitcher.generalTab.status="Status"
AdvSceneSwitcher.generalTab.status.hotkeytips="Hotkeys can be defined in the OBS settings"
AdvSceneSwitcher.generalTab.status.currentStatus="Advanced Scene Switcher is:"
AdvSceneSwitcher.generalTab.status.onStartup="On startup:"
AdvSceneSwitcher.generalTab.status.onStartup="On startup of OBS:"
AdvSceneSwitcher.generalTab.status.onStartup.asLastRun="Start the scene switcher if it was running"
AdvSceneSwitcher.generalTab.status.onStartup.alwaysStart="Always start the scene switcher"
AdvSceneSwitcher.generalTab.status.onStartup.doNotStart="Do not start the scene switcher"
AdvSceneSwitcher.generalTab.status.start="Start"
AdvSceneSwitcher.generalTab.status.stop="Stop"
AdvSceneSwitcher.generalTab.status.autoStart="Automatically start the scene switcher when:"
AdvSceneSwitcher.generalTab.status.autoStart.never="Never"
AdvSceneSwitcher.generalTab.status.autoStart.recording="Recording"
AdvSceneSwitcher.generalTab.status.autoStart.streaming="Streaming"
AdvSceneSwitcher.generalTab.status.autoStart.recordingAndStreaming="Recording or Streaming"
AdvSceneSwitcher.generalTab.status.checkInterval="Check switch conditions every"
AdvSceneSwitcher.generalTab.generalBehavior="General behavior"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recording="Recording"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.streaming="Streaming"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recordingAndStreaming="Recording and Streaming"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart1="Automatically start"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart2="on scene"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet="If no switch condition is met for"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMetDelayTooltip="Will only ever be as accurate as the configured check interval."
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.dontSwitch="Don't switch"
@@ -27,7 +27,7 @@ AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo="Switch to:"
AdvSceneSwitcher.generalTab.generalBehavior.cooldown="After a match do not switch scenes for"
AdvSceneSwitcher.generalTab.generalBehavior.cooldownHint="During this time potential matches will be ignored!"
AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging="Enable verbose logging"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStop="Automatically stop streaming/recording on scene"
AdvSceneSwitcher.generalTab.generalBehavior.saveWindowGeo="Save window position and size"
AdvSceneSwitcher.generalTab.generalBehavior.disableUIHints="Disable UI hints"
AdvSceneSwitcher.generalTab.priority="Priority"
AdvSceneSwitcher.generalTab.priority.description="Switching methods priority (Highest priority is at the top)"
@@ -50,15 +50,127 @@ AdvSceneSwitcher.generalTab.priority.windowTitle="Window Title"
AdvSceneSwitcher.generalTab.priority.media="Media"
AdvSceneSwitcher.generalTab.priority.time="Time"
AdvSceneSwitcher.generalTab.priority.audio="Audio"
AdvSceneSwitcher.generalTab.priority.video="Video"
AdvSceneSwitcher.generalTab.priority.macro="Macro"
; Macro Tab
AdvSceneSwitcher.macroTab.title="Macro"
AdvSceneSwitcher.macroTab.macros="Macros"
AdvSceneSwitcher.macroTab.help="Macros allow you to execute a string of actions depending on multiple conditions.\n\nClick on the highlighted plus symbol to add a new Macro."
AdvSceneSwitcher.macroTab.editConditionHelp="This section allows you to define Macro conditions.\n\nSelect an existing or add a new Macro on the left."
AdvSceneSwitcher.macroTab.editActionHelp="This section allows you to define Macro actions.\n\nSelect an existing or add a new Macro on the left."
AdvSceneSwitcher.macroTab.edit="Edit macro"
AdvSceneSwitcher.macroTab.edit.logic="Logic type:"
AdvSceneSwitcher.macroTab.edit.condition="Condition type:"
AdvSceneSwitcher.macroTab.edit.action="Action type:"
AdvSceneSwitcher.macroTab.add="Add new macro"
AdvSceneSwitcher.macroTab.name="Name:"
AdvSceneSwitcher.macroTab.defaultname="Macro %1"
AdvSceneSwitcher.macroTab.exists="Macro name exists already"
AdvSceneSwitcher.macroTab.copy="Create copy"
; Macro Logic
AdvSceneSwitcher.logic.none="Ignore entry"
AdvSceneSwitcher.logic.and="And"
AdvSceneSwitcher.logic.or="Or"
AdvSceneSwitcher.logic.andNot="And not"
AdvSceneSwitcher.logic.orNot="Or not"
AdvSceneSwitcher.logic.rootNone="If"
AdvSceneSwitcher.logic.not="If not"
; Macro Conditions
AdvSceneSwitcher.condition.audio="Audio"
AdvSceneSwitcher.ondition.audio.state.below="Below"
AdvSceneSwitcher.ondition.audio.state.above="Above"
AdvSceneSwitcher.condition.audio.entry="Volume of {{audioSources}} is {{condition}} {{volume}} for {{duration}} seconds"
AdvSceneSwitcher.condition.region="Screen region"
AdvSceneSwitcher.condition.region.entry="Cursor is in {{minX}} {{minY}} x {{maxX}} {{maxY}}"
AdvSceneSwitcher.condition.scene="Scene"
AdvSceneSwitcher.condition.scene.type.current="Current"
AdvSceneSwitcher.condition.scene.type.previous="Previous"
AdvSceneSwitcher.condition.scene.entry="{{sceneType}} scene is {{scenes}} for {{duration}}"
AdvSceneSwitcher.condition.window="Window"
AdvSceneSwitcher.condition.window.entry.line1="{{windows}} exist and ..."
AdvSceneSwitcher.condition.window.entry.line2="... is {{fullscreen}} fullscreen {{maximized}} maximized {{focused}} focused"
AdvSceneSwitcher.condition.file="File"
AdvSceneSwitcher.condition.file.entry.line1="Content of {{fileType}} {{filePath}} {{browseButton}} matches:"
AdvSceneSwitcher.condition.file.entry.line2="{{matchText}}"
AdvSceneSwitcher.condition.file.entry.line3="{{useRegex}} {{checkModificationDate}} {{checkFileContent}}"
AdvSceneSwitcher.condition.media="Media"
AdvSceneSwitcher.condition.media.entry="{{mediaSources}} state is {{states}} and {{timeRestrictions}} {{time}}"
AdvSceneSwitcher.condition.video="Video"
AdvSceneSwitcher.condition.video.condition.match="exactly matches"
AdvSceneSwitcher.condition.video.condition.differ="does not match"
AdvSceneSwitcher.condition.video.condition.hasChanged="has changed"
AdvSceneSwitcher.condition.video.condition.hasNotChanged="has not changed"
AdvSceneSwitcher.condition.video.condition.noImage="has no output"
AdvSceneSwitcher.condition.video.askFileAction="Do you want to use an existing file or create a screenshot of the currently selected source?"
AdvSceneSwitcher.condition.video.askFileAction.file="Use existing file"
AdvSceneSwitcher.condition.video.askFileAction.screenshot="Create screenshot"
AdvSceneSwitcher.condition.video.entry="{{videoSources}} {{condition}} {{filePath}} {{browseButton}} for {{duration}}"
AdvSceneSwitcher.condition.stream="Streaming"
AdvSceneSwitcher.condition.stream.state.start="Stream running"
AdvSceneSwitcher.condition.stream.state.stop="Stream stopped"
AdvSceneSwitcher.condition.stream.entry="{{streamState}} for {{duration}}"
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}} for {{duration}}"
AdvSceneSwitcher.condition.process="Process"
AdvSceneSwitcher.condition.process.entry="{{processes}} is running {{focused}} and is focused"
AdvSceneSwitcher.condition.idle="Idle"
AdvSceneSwitcher.condition.idle.entry="No keyboard or mouse inputs for {{duration}}"
AdvSceneSwitcher.condition.pluginState="Plugin state"
AdvSceneSwitcher.condition.pluginState.state.sceneSwitched="Automated scene change was triggered in this interval"
AdvSceneSwitcher.condition.pluginState.entry="{{condition}}"
; Macro Actions
AdvSceneSwitcher.action.switchScene="Switch scene"
AdvSceneSwitcher.action.scene.entry="Switch to scene {{scenes}} using {{transitions}} with a duration of {{duration}} seconds"
AdvSceneSwitcher.action.wait="Wait"
AdvSceneSwitcher.action.wait.type.fixed="fixed"
AdvSceneSwitcher.action.wait.type.random="random"
AdvSceneSwitcher.action.wait.entry.fixed="Wait for {{waitType}} duration of {{duration}}"
AdvSceneSwitcher.action.wait.entry.random="Wait for {{waitType}} duration from {{duration}} to {{duration2}}"
AdvSceneSwitcher.action.audio="Audio"
AdvSceneSwitcher.action.audio.type.mute="Mute"
AdvSceneSwitcher.action.audio.type.unmute="Unmute"
AdvSceneSwitcher.action.audio.type.sourceVolume="Set source volume"
AdvSceneSwitcher.action.audio.type.masterVolume="Set master volume"
AdvSceneSwitcher.action.audio.entry="{{actions}} {{audioSources}} {{volume}}"
AdvSceneSwitcher.action.recording="Recording"
AdvSceneSwitcher.action.recording.type.stop="Stop recording"
AdvSceneSwitcher.action.recording.type.start="Start recording"
AdvSceneSwitcher.action.recording.type.pause="Pause recording"
AdvSceneSwitcher.action.recording.type.unpause="Unpause recording"
AdvSceneSwitcher.action.recording.pause.hint="Note that depending on your recording settings you might not be able to pause recording"
AdvSceneSwitcher.action.recording.entry="{{actions}}{{pauseHint}}"
AdvSceneSwitcher.action.replay="Replay buffer"
AdvSceneSwitcher.action.replay.type.stop="Stop replay buffer"
AdvSceneSwitcher.action.replay.type.start="Start replay buffer"
AdvSceneSwitcher.action.replay.type.save="Save replay buffer"
AdvSceneSwitcher.action.replay.entry="{{actions}}"
AdvSceneSwitcher.action.streaming="Streaming"
AdvSceneSwitcher.action.streaming.type.stop="Stop streaming"
AdvSceneSwitcher.action.streaming.type.start="Start streaming"
AdvSceneSwitcher.action.streaming.entry="{{actions}}"
AdvSceneSwitcher.action.run="Run"
AdvSceneSwitcher.action.run.entry="Run {{filePath}} {{browseButton}}"
; Transition Tab
AdvSceneSwitcher.transitionTab.title="Transition"
AdvSceneSwitcher.transitionTab.transitionOverride="Scene transitions defined in the scene switcher take priority over Transition Overrides defined per scene"
AdvSceneSwitcher.transitionTab.setTransitionBy="When changing transitions:"
AdvSceneSwitcher.transitionTab.transitionOverride="Set transition overrides"
AdvSceneSwitcher.transitionTab.adjustActiveTransitionType="Change active transition type"
AdvSceneSwitcher.transitionTab.transitionBehaviorSelectionError="At least one option must be enabled:\n\n - Use transition overrides\n\n - Change active transition type"
AdvSceneSwitcher.transitionTab.transitionForAToB="Use transition for automated scene switch from scene A to scene B"
AdvSceneSwitcher.transitionTab.transitionForAToB.description="<html><head/><body><p>These settings <span style=\"font-style:italic;\">only</span> affect transitions caused by the scene switcher - Check out <a href=\"https://obsproject.com/forum/resources/transition-table.1174/\"><span style=\" text-decoration: underline; color:#268bd2;\">Transition Table</span></a> if you want to configure this for manual scene changes.<br/>Settings defined here take priority over transition settings configured elsewhere in the scene switcher.</p></body></html>"
AdvSceneSwitcher.transitionTab.transitionsHelp="<html><head/><body><p>These settings <span style=\"font-style:italic;\">only</span> affect transitions caused by the scene switcher - Check out <a href=\"https://obsproject.com/forum/resources/transition-table.1174/\"><span style=\" text-decoration: underline; color:#268bd2;\">Transition Table</span></a> if you want to configure this for manual scene changes.<br/>Settings defined here take priority over transition settings configured elsewhere in the scene switcher.<br/><br/>Click the plus symbol below to add a new entry.</p></body></html>"
AdvSceneSwitcher.transitionTab.defaultTransition="Change transition if scene is active"
AdvSceneSwitcher.transitionTab.entry="Switch from {{scenes}} to {{scenes2}} using {{transitions}}"
AdvSceneSwitcher.transitionTab.entry="Switch from {{scenes}} to {{scenes2}} using {{transitions}} with a duration of {{duration}}"
AdvSceneSwitcher.transitionTab.defaultTransitionEntry="When scene {{scenes}} is active change default scene transition to {{transitions}}"
AdvSceneSwitcher.transitionTab.defaultTransitionsHelp="Click on the plus symbol to add an entry."
AdvSceneSwitcher.transitionTab.defaultTransition.delay="Switch transition {{defTransitionDelay}} after scene change."
AdvSceneSwitcher.transitionTab.defaultTransition.delay.help="The delay is used to avoid cancelled scene switches, which can happen if the transition type is changed while a transition is still ongoing."
; Pause Scenes Tab
AdvSceneSwitcher.pauseTab.title="Pause"
@@ -69,6 +181,7 @@ AdvSceneSwitcher.pauseTab.pauseTypeScene="scene is active"
AdvSceneSwitcher.pauseTab.pauseTypeWindow="window is in focus"
AdvSceneSwitcher.pauseTab.pauseTargetAll="all"
AdvSceneSwitcher.pauseTab.pauseEntry="Pause {{pauseTargets}} checks when {{pauseTypes}} {{scenes}} {{windows}}"
AdvSceneSwitcher.pauseTab.help="On this tab you can configure to pause individual switching methods if a scene is active or window is in focus.\n\nClick on the highlighted plus symbol to continue."
; Window Title Tab
AdvSceneSwitcher.windowTitleTab.title="Title"
@@ -79,19 +192,24 @@ AdvSceneSwitcher.windowTitleTab.fullscreen="if fullscreen"
AdvSceneSwitcher.windowTitleTab.maximized="if maximized"
AdvSceneSwitcher.windowTitleTab.focused="if focused"
AdvSceneSwitcher.windowTitleTab.entry="{{windows}} {{scenes}} {{transitions}} {{fullscreen}} {{maximized}} {{focused}}"
AdvSceneSwitcher.windowTitleTab.windowsHelp="Switch scenes based on the window title of running applications.\nThe following additional conditions can be selected:\nThe window is Fullscreen\nThe window is maximized\nThe window is focused\n\nClick on the highlighted plus symbol to continue."
AdvSceneSwitcher.windowTitleTab.ignoreWindowsHelp="If a window title is ignored the scene switcher will act as if the previously selected window is still in focus.\nThis will allow you to avoid scene switches, if you frequently switch to a different window, which shall not trigger a scene change.\n\nChoose a window or enter a window title above and click on the plus symbol below to add it to the list."
; Executable Tab
AdvSceneSwitcher.executableTab.title="Executable"
AdvSceneSwitcher.executableTab.implemented="Implemented by dasOven"
AdvSceneSwitcher.executableTab.requiresFocus="only if focused"
AdvSceneSwitcher.executableTab.entry="When {{processes}} is running switch to {{scenes}} using {{transitions}} {{requiresFocus}}"
AdvSceneSwitcher.executableTab.help="This tab will allow you to automatically switch scenes if a process is running.\nThis can be useful in situations where the window name could change or is not known.\n\nClick on the highlighted plus symbol to continue."
; Screen Region Tab
AdvSceneSwitcher.screenRegionTab.title="Region"
AdvSceneSwitcher.screenRegionTab.currentPosition="Cursor is currently at:"
AdvSceneSwitcher.screenRegionTab.showGuideFrames="Show guide frames"
AdvSceneSwitcher.screenRegionTab.hideGuideFrames="Hide guide frames"
AdvSceneSwitcher.screenRegionTab.entry="If cursor is in {{minX}} {{minY}} x {{maxX}} {{maxY}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.screenRegionTab.excludeScenes.None="No selection"
AdvSceneSwitcher.screenRegionTab.entry="If cursor is in {{minX}} {{minY}} x {{maxX}} {{maxY}} switch to {{scenes}} using {{transitions}} unless in {{excludeScenes}}"
AdvSceneSwitcher.screenRegionTab.help="This tab will allow you to automatically switch scenes based on the current position of your mouse cursor.\n\nClick on the highlighted plus symbol to continue."
; Media Tab
AdvSceneSwitcher.mediaTab.title="Media"
@@ -112,6 +230,7 @@ AdvSceneSwitcher.mediaTab.timeRestriction.longer="Time longer"
AdvSceneSwitcher.mediaTab.timeRestriction.remainShorter="Time remaining shorter"
AdvSceneSwitcher.mediaTab.timeRestriction.remainLonger="Time remaining longer"
AdvSceneSwitcher.mediaTab.entry="When {{mediaSources}} state is {{states}} and {{timeRestrictions}} {{time}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.mediaTab.help="This tab will allow you to switch scenes based on the states of media sources.\nFor example, you can automatically switch back to the previous scene once the selected media sourced ended its playback.\n\nClick on the highlighted plus symbol to continue."
; File Tab
AdvSceneSwitcher.fileTab.title="File"
@@ -136,11 +255,13 @@ AdvSceneSwitcher.fileTab.checkfileContent="if content changed"
AdvSceneSwitcher.fileTab.entry="Switch to {{scenes}} using {{transitions}} if content of {{fileType}} {{filePath}} {{browseButton}} matches:"
AdvSceneSwitcher.fileTab.entry2="{{matchText}}"
AdvSceneSwitcher.fileTab.entry3="{{useRegex}} {{checkModificationDate}} {{checkFileContent}}"
AdvSceneSwitcher.fileTab.help="This tab will allow you to automatically switch scenes based on the content of remote or local files.\n\nClick on the highlighted plus symbol to continue."
; Random Tab
AdvSceneSwitcher.randomTab.title="Random"
AdvSceneSwitcher.randomTab.randomDisabledWarning="Functionality disabled - To activate select \"If no switch condition is met switch to any scene in Random tab\" on General tab"
AdvSceneSwitcher.randomTab.entry="If no switch condition is met switch to {{scenes}} using {{transitions}} for {{delay}}"
AdvSceneSwitcher.randomTab.help="The scene switcher will randomly choose an entry on this tab to switch to for the configured time.\nNote that the same entry will not be chosen twice in a row.\n\nClick on the highlighted plus symbol to continue."
; Time Tab
AdvSceneSwitcher.timeTab.title="Time"
@@ -155,15 +276,12 @@ AdvSceneSwitcher.timeTab.sundays="Sundays"
AdvSceneSwitcher.timeTab.afterstart="After streaming/recording start"
AdvSceneSwitcher.timeTab.afterstart.tip="The time relative to the start of streaming / recording will be used"
AdvSceneSwitcher.timeTab.entry="{{triggers}} at {{time}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.timeTab.help="This tab will allow you to automatically switch to a different scene based on the current local time.\n\nNote that the scene switcher will only switch scenes at the exact time you specified.\nMake sure you have configured the priority settings on the General tab to your liking so the selected time point will not be missed due to other switching methods having a higher priority.\n\nClick on the highlighted plus symbol to continue."
; Idle Tab
AdvSceneSwitcher.idleTab.title="Idle"
AdvSceneSwitcher.idleTab.enable="Enable Idle Detection"
AdvSceneSwitcher.idleTab.condition1="After "
AdvSceneSwitcher.idleTab.condition2="of no keyboard or mouse inputs "
AdvSceneSwitcher.idleTab.switchToScene="switch to scene"
AdvSceneSwitcher.idleTab.usingTransition1="using the"
AdvSceneSwitcher.idleTab.usingTransition2="transition"
AdvSceneSwitcher.idleTab.idleswitch="After {{duration}} of no keyboard or mouse inputs switch to scene {{scenes}} using the {{transitions}}"
AdvSceneSwitcher.idleTab.dontSwitchIfFocus1="Do not switch if"
AdvSceneSwitcher.idleTab.dontSwitchIfFocus2="is in focus"
@@ -179,29 +297,116 @@ AdvSceneSwitcher.sceneSequenceTab.loadSuccess="Advanced Scene Switcher settings
AdvSceneSwitcher.sceneSequenceTab.fileType="Text files (*.txt)"
AdvSceneSwitcher.sceneSequenceTab.interruptible="interruptible"
AdvSceneSwitcher.sceneSequenceTab.interruptibleHint="Other switching methods are allowed to interrupt this scene sequence"
AdvSceneSwitcher.sceneSequenceTab.entry="When {{startScenes}} is active switch to {{scenes}} after {{delay}} {{delayUnits}} using {{transitions}} {{interruptible}}"
AdvSceneSwitcher.sceneSequenceTab.entry="When {{startScenes}} is active switch to {{scenes}} after {{delay}} using {{transitions}} {{interruptible}}"
AdvSceneSwitcher.sceneSequenceTab.extendEdit="Extend Sequence"
AdvSceneSwitcher.sceneSequenceTab.extendEntry="After {{delay}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.sceneSequenceTab.help="This tab will allow you to automatically switch to a different scene if a scene was active for a configured period of time.\nFor example, you could automatically cycle back and forth between two scenes automatically.\n\nClick on the highlighted plus symbol to continue."
; Audio Tab
AdvSceneSwitcher.audioTab.title="Audio"
AdvSceneSwitcher.audioTab.condition.above="above"
AdvSceneSwitcher.audioTab.condition.below="below"
AdvSceneSwitcher.audioTab.entry="When the volume of {{audioSources}} is {{condition}} {{volumeWidget}} for {{duration}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.audioTab.ignoreInactiveSource="unless source is inactive"
AdvSceneSwitcher.audioTab.entry="When the volume of {{audioSources}} is {{condition}} {{volumeWidget}} for {{duration}} seconds switch to {{scenes}} using {{transitions}} {{ignoreInactiveSource}}"
AdvSceneSwitcher.audioTab.multiMatchfallbackCondition="If multiple entries match ..."
AdvSceneSwitcher.audioTab.multiMatchfallback="... for {{duration}} switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.audioTab.multiMatchfallback="... for {{duration}} seconds switch to {{scenes}} using {{transitions}}"
AdvSceneSwitcher.audioTab.help="This tab will allow you to switch scenes based on the volume of sources.\nFor example, you could automatically switch to a different scene if the volume of your microphone reaches a certain threshold.\n\nClick on the highlighted plus symbol to continue."
; Video Tab
AdvSceneSwitcher.videoTab.title="Video"
AdvSceneSwitcher.videoTab.getScreenshot="Get screenshot for selected entry"
AdvSceneSwitcher.videoTab.getScreenshotHelp="Get Screenshot of the currently selected entry's video source and automatically set it as the target image"
AdvSceneSwitcher.videoTab.condition.match="exactly matches"
AdvSceneSwitcher.videoTab.condition.match.tooltip="An exact match requires the target and the source image to be of the same resolution.\nAdditionally every single pixel needs to match, which is why use of image formats which use compression (e.g. .JPG) is not recommended!"
AdvSceneSwitcher.videoTab.condition.differ="does not match"
AdvSceneSwitcher.videoTab.condition.hasNotChanged="has not changed"
AdvSceneSwitcher.videoTab.condition.hasChanged="has changed"
AdvSceneSwitcher.videoTab.ignoreInactiveSource="unless source is inactive"
AdvSceneSwitcher.videoTab.entry="When {{videoSources}} {{condition}} {{filePath}} {{browseButton}} for {{duration}} switch to {{scenes}} using {{transitions}} {{ignoreInactiveSource}}"
AdvSceneSwitcher.videoTab.help="<html><head/><body><p>This tab will allow you to switch scenes based on the current video output of selected sources.<br/>Make sure to check out <a href=\"https://obsproject.com/forum/resources/pixel-match-switcher.1202/\"><span style=\" text-decoration: underline; color:#268bd2;\">Pixel Match Switcher</span></a> for an even better implementation of this functionality.<br/><br/> Click on the highlighted plus symbol to continue.</p></body></html>"
; Network Tab
AdvSceneSwitcher.networkTab.title="Network"
AdvSceneSwitcher.networkTab.warning="Running the server outside of a local network will allow third parties to read the active scene."
AdvSceneSwitcher.networkTab.DisabledWarning="This functionality unfortunately had to be disabled on macOS due to library incompatibilities when running the obs-websocket plugin in parallel."
AdvSceneSwitcher.networkTab.server="Start server (Sends scene switch messages to all connected clients)"
AdvSceneSwitcher.networkTab.server.port="Port"
AdvSceneSwitcher.networkTab.server.lockToIPv4="Lock server to only using IPv4"
AdvSceneSwitcher.networkTab.server.restrictSendToAutomatedSwitches="Only send messages for automated scene switches"
AdvSceneSwitcher.networkTab.startFailed.message="The WebSockets server failed to start, maybe because:\n - TCP port %1 may currently be in use elsewhere on this system, possibly by another application. Try setting a different TCP port in the WebSocket server settings, or stop any application that could be using this port.\n - Error message: %2"
AdvSceneSwitcher.networkTab.server.status.currentStatus="Current status"
AdvSceneSwitcher.networkTab.server.status.notRunning="Not running"
AdvSceneSwitcher.networkTab.server.status.starting="Starting"
AdvSceneSwitcher.networkTab.server.status.running="Running"
AdvSceneSwitcher.networkTab.server.restart="Restart server"
AdvSceneSwitcher.networkTab.client="Start client (Receives scene switches messages)"
AdvSceneSwitcher.networkTab.client.address="Hostname or IP address"
AdvSceneSwitcher.networkTab.client.port="Port"
AdvSceneSwitcher.networkTab.client.status.currentStatus="Current status"
AdvSceneSwitcher.networkTab.client.status.disconnected="Disconnected"
AdvSceneSwitcher.networkTab.client.status.connecting="Connecting"
AdvSceneSwitcher.networkTab.client.status.connected="Connected"
AdvSceneSwitcher.networkTab.client.reconnect="Force reconnect"
; Scene Group Tab
AdvSceneSwitcher.sceneGroupTab.title="Scene Group"
AdvSceneSwitcher.sceneGroupTab.list="Scene Groups"
AdvSceneSwitcher.sceneGroupTab.edit="Edit Scene Groups"
AdvSceneSwitcher.sceneGroupTab.edit.name="Name:"
AdvSceneSwitcher.sceneGroupTab.edit.type="Type: {{type}}"
AdvSceneSwitcher.sceneGroupTab.type.count="Count"
AdvSceneSwitcher.sceneGroupTab.type.time="Time"
AdvSceneSwitcher.sceneGroupTab.type.random="Random"
AdvSceneSwitcher.sceneGroupTab.edit.count="Advance to next scene in list after {{count}} matches"
AdvSceneSwitcher.sceneGroupTab.edit.time="Advance to next scene in list after {{time}} has passed"
AdvSceneSwitcher.sceneGroupTab.edit.random="Choose next scene in list at random"
AdvSceneSwitcher.sceneGroupTab.edit.repeat="Start from beginning if end of scene list is reached"
AdvSceneSwitcher.sceneGroupTab.edit.addScene="Add scene"
AdvSceneSwitcher.sceneGroupTab.add="Add Scene Group"
AdvSceneSwitcher.sceneGroupTab.defaultname="Scene Group %1"
AdvSceneSwitcher.sceneGroupTab.exists="Scene Group or Scene name exists already"
AdvSceneSwitcher.sceneGroupTab.help="Scene Groups can be selected as a target just like a regular scene.\n\nAs the name suggests a scene group is a collection of multiple scenes.\nThe scene group will advance through the list of its assigned scenes depending on the configured settings, which can be found on the right side.\n\nYou can configure the scene group to advance to the next scene in the list:\nAfter a number of times the scene group is selected as a target.\nAfter a certain amount of time has passed.\nOr randomly.\n\nFor example, a scene group containing the scenes ...\nScene 1\nScene 2\nScene 3 \n... will activate \"Scene 1\" the first time it is selected as a target.\nThe second time it will activate \"Scene 2\".\nThe remaining times \"Scene 3\" will be activated.\n\nClick the highlighted plus symbol below to add a new scene group."
AdvSceneSwitcher.sceneGroupTab.scenes.help="Select the scene group you want to modify on the left.\n\nSelect a scene to add to this scene group by selecting the scene above and clicking the plus symbol below.\n\nA scene can be added multiple times to the same scene group."
; Scene Trigger Tab
AdvSceneSwitcher.sceneTriggerTab.title="Scene Triggers"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.none="--select trigger--"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneActive="is active"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneInactive="is not active"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneLeave="switched away from"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.none="--select action--"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startRecording="start recording"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.pauseRecording="pause recording"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unpauseRecording="unpause recording"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopRecording="stop recording"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopStreaming="stop streaming"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startStreaming="start streaming"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startReplayBuffer="start replay buffer"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopReplayBuffer="stop replay buffer"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.muteSource="mute source"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unmuteSource="unmute source"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startSwitcher="start the scene switcher"
AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopSwitcher="stop the scene switcher"
AdvSceneSwitcher.sceneTriggerTab.entry="When {{scenes}} {{triggers}} {{actions}} {{audioSources}} after {{duration}}"
AdvSceneSwitcher.sceneTriggerTab.help="This tab allows you to trigger actions on scene changes, like stopping recording or streaming."
; Hotkey
AdvSceneSwitcher.hotkey.startSwitcherHotkey="Start the Advanced Scene Switcher"
AdvSceneSwitcher.hotkey.stopSwitcherHotkey="Stop the Advanced Scene Switcher"
AdvSceneSwitcher.hotkey.startStopToggleSwitcherHotkey="Toggle Start/Stop for the Advanced Scene Switcher"
AdvSceneSwitcher.askBackup="Detected a new version of the Advanced Scene Switcher.\nShould a backup of the old settings be created?"
AdvSceneSwitcher.close="Close"
AdvSceneSwitcher.browse="Browse"
AdvSceneSwitcher.selectScene="--select scene--"
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
AdvSceneSwitcher.currentTransition="Current Transition"
AdvSceneSwitcher.selectTransition="--select transition--"
AdvSceneSwitcher.selectWindow="--select window--"
AdvSceneSwitcher.selectAudioSource="--select audio source--"
AdvSceneSwitcher.selectVideoSource="--select video source--"
AdvSceneSwitcher.selectMediaSource="--select media source--"
AdvSceneSwitcher.selectProcess="--select process--"
AdvSceneSwitcher.enterPath="--enter path--"

View File

@@ -12,20 +12,17 @@ AdvSceneSwitcher.generalTab.status.onStartup.alwaysStart="总是自动启动"
AdvSceneSwitcher.generalTab.status.onStartup.doNotStart="不要启动"
AdvSceneSwitcher.generalTab.status.start="启动"
AdvSceneSwitcher.generalTab.status.stop="停止"
AdvSceneSwitcher.generalTab.status.autoStart.recording="录制"
AdvSceneSwitcher.generalTab.status.autoStart.streaming="推流"
AdvSceneSwitcher.generalTab.status.autoStart.recordingAndStreaming="录制和推流"
AdvSceneSwitcher.generalTab.status.checkInterval="检查切换条件时间间隔"
AdvSceneSwitcher.generalTab.generalBehavior="一般表现"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recording="录制"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.streaming="推流"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart.recordingAndStreaming="录制和推流"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart1="自动开始"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStart2="当切换到场景时"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet="如果不符合任何切换条件"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMetDelayTooltip="时间精度最高只能达到配置的轮询间隔"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.dontSwitch="不切换"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchToRandom="切换到随机场景列表中任意随机场景"
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo="切换到"
AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging="详细日志输出"
AdvSceneSwitcher.generalTab.generalBehavior.automaticallyStop="当切换到场景时自动停止推流和录制"
AdvSceneSwitcher.generalTab.generalBehavior.disableUIHints="禁用UI提示"
AdvSceneSwitcher.generalTab.priority="优先级"
AdvSceneSwitcher.generalTab.priority.description="切换场景优先级 (最上方的项优先级最高)"
@@ -53,7 +50,7 @@ AdvSceneSwitcher.generalTab.priority.audio="音频"
AdvSceneSwitcher.transitionTab.title="转场特效"
AdvSceneSwitcher.transitionTab.transitionOverride="在场景切换器中设定的转场特效优先级高于场景设定的转场特效"
AdvSceneSwitcher.transitionTab.transitionForAToB="当自动从场景A切换到场景B时使用的转场特效"
AdvSceneSwitcher.transitionTab.transitionForAToB.description="<html><head/><body><p>这里的设定<span style=\"font-style:bold;\">只影响由场景切换器引起的转场有效</span>,不影响你手动的引起的转场。<br/>在这里设定的转场特效优先级高于场景切换器其他地方设置的</p></body></html>"
AdvSceneSwitcher.transitionTab.transitionsHelp="<html><head/><body><p>这里的设定<span style=\"font-style:bold;\">只影响由场景切换器引起的转场有效</span>,不影响你手动的引起的转场。<br/>在这里设定的转场特效优先级高于场景切换器其他地方设置的<br/><br/>Click the plus symbol below to continue.</p></body></html>"
AdvSceneSwitcher.transitionTab.defaultTransition="当切换到这个场景时修改默认转场特效"
AdvSceneSwitcher.transitionTab.switchDefaultLabel="活跃时切换默认转场特效为"
AdvSceneSwitcher.transitionTab.entry="从场景 {{scenes}} 切换到场景 {{scenes2}} 时使用转场特效 {{transitions}}"
@@ -86,7 +83,7 @@ AdvSceneSwitcher.screenRegionTab.title="屏幕区域"
AdvSceneSwitcher.screenRegionTab.currentPosition="鼠标当前位置:"
AdvSceneSwitcher.screenRegionTab.showGuideFrames="显示区域边界"
AdvSceneSwitcher.screenRegionTab.hideGuideFrames="隐藏区域边界"
AdvSceneSwitcher.screenRegionTab.entry="如果鼠标在 {{minX}} {{minY}} x {{maxX}} {{maxY}} 使用转场特效 {{transitions}} 切换到场景 {{scenes}}"
AdvSceneSwitcher.screenRegionTab.entry="如果鼠标在 {{minX}} {{minY}} x {{maxX}} {{maxY}} 使用转场特效 {{transitions}} 切换到场景 {{scenes}} unless in {{excludeScenes}}"
; Media Tab
AdvSceneSwitcher.mediaTab.title="媒体"
@@ -171,7 +168,7 @@ AdvSceneSwitcher.sceneSequenceTab.loadTitle="从文件加载序列 ..."
AdvSceneSwitcher.sceneSequenceTab.loadFail="导入失败"
AdvSceneSwitcher.sceneSequenceTab.loadSuccess="导入失败成功"
AdvSceneSwitcher.sceneSequenceTab.fileType="文本文件 (*.txt)"
AdvSceneSwitcher.sceneSequenceTab.entry="当场景 {{startScenes}} 被激活 {{delay}} {{delayUnits}}后使用转场特效 {{transitions}} 切换到场景 {{scenes}} {{interruptible}}"
AdvSceneSwitcher.sceneSequenceTab.entry="当场景 {{startScenes}} 被激活 {{delay}} 后使用转场特效 {{transitions}} 切换到场景 {{scenes}} {{interruptible}}"
; Audio Tab
AdvSceneSwitcher.audioTab.title="音频"

1
deps/asio vendored Submodule

Submodule deps/asio added at b73dc1d2c0

1
deps/websocketpp vendored Submodule

Submodule deps/websocketpp added at c6d7e295bf

File diff suppressed because it is too large Load Diff

View File

@@ -11,13 +11,14 @@
#include "headers/advanced-scene-switcher.hpp"
#include "headers/curl-helper.hpp"
#include "headers/utility.hpp"
#include "headers/version.h"
SwitcherData *switcher = nullptr;
/********************************************************************************
/******************************************************************************
* Create the Advanced Scene Switcher settings window
********************************************************************************/
******************************************************************************/
AdvSceneSwitcher::AdvSceneSwitcher(QWidget *parent)
: QDialog(parent), ui(new Ui_AdvSceneSwitcher)
{
@@ -38,8 +39,9 @@ bool translationAvailable()
void AdvSceneSwitcher::loadUI()
{
if (!translationAvailable()) {
DisplayMessage("Failed to find plug-in's 'data' directory.\n"
"Please check installation instructions!");
(void)DisplayMessage(
"Failed to find plug-in's 'data' directory.\n"
"Please check installation instructions!");
}
#if __APPLE__
@@ -58,25 +60,24 @@ void AdvSceneSwitcher::loadUI()
setupFileTab();
setupTimeTab();
setupAudioTab();
setupVideoTab();
setupNetworkTab();
setupSceneGroupTab();
setupTriggerTab();
setupMacroTab();
setTabOrder();
restoreWindowGeo();
loading = false;
}
/********************************************************************************
/******************************************************************************
* UI helpers
********************************************************************************/
void AdvSceneSwitcher::DisplayMessage(QString msg)
{
QMessageBox Msgbox;
Msgbox.setWindowTitle("Advanced Scene Switcher");
Msgbox.setText(msg);
Msgbox.exec();
}
void addSelectionEntry(QComboBox *sel, const char *description,
const char *tooltip = "")
******************************************************************************/
void AdvSceneSwitcher::addSelectionEntry(QComboBox *sel,
const char *description,
bool selectable, const char *tooltip)
{
sel->addItem(description);
@@ -89,18 +90,30 @@ void addSelectionEntry(QComboBox *sel, const char *description,
QModelIndex firstIndex =
model->index(0, sel->modelColumn(), sel->rootModelIndex());
QStandardItem *firstItem = model->itemFromIndex(firstIndex);
firstItem->setSelectable(false);
firstItem->setEnabled(false);
if (!selectable) {
firstItem->setSelectable(false);
firstItem->setEnabled(false);
}
}
void AdvSceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious,
bool addSelect)
bool addSceneGroup,
bool addSelect,
std::string selectText,
bool selectable)
{
if (addSelect)
addSelectionEntry(
sel, obs_module_text("AdvSceneSwitcher.selectScene"),
obs_module_text(
"AdvSceneSwitcher.invaildEntriesWillNotBeSaved"));
if (addSelect) {
if (selectText.empty()) {
addSelectionEntry(
sel,
obs_module_text("AdvSceneSwitcher.selectScene"),
selectable,
obs_module_text(
"AdvSceneSwitcher.invaildEntriesWillNotBeSaved"));
} else {
addSelectionEntry(sel, selectText.c_str(), selectable);
}
}
BPtr<char *> scenes = obs_frontend_get_scene_names();
char **temp = scenes;
@@ -110,18 +123,34 @@ void AdvSceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious,
temp++;
}
if (addPrevious)
if (addPrevious) {
sel->addItem(obs_module_text(
"AdvSceneSwitcher.selectPreviousScene"));
}
if (addSceneGroup) {
for (auto &sg : switcher->sceneGroups) {
sel->addItem(QString::fromStdString(sg.name));
}
}
}
void AdvSceneSwitcher::populateTransitionSelection(QComboBox *sel,
bool addSelect)
bool addCurrent,
bool addSelect,
bool selectable)
{
if (addSelect)
if (addSelect) {
addSelectionEntry(
sel,
obs_module_text("AdvSceneSwitcher.selectTransition"));
obs_module_text("AdvSceneSwitcher.selectTransition"),
selectable);
}
if (addCurrent) {
sel->addItem(
obs_module_text("AdvSceneSwitcher.currentTransition"));
}
obs_frontend_source_list *transitions = new obs_frontend_source_list();
obs_frontend_get_transitions(transitions);
@@ -137,9 +166,10 @@ void AdvSceneSwitcher::populateTransitionSelection(QComboBox *sel,
void AdvSceneSwitcher::populateWindowSelection(QComboBox *sel, bool addSelect)
{
if (addSelect)
if (addSelect) {
addSelectionEntry(
sel, obs_module_text("AdvSceneSwitcher.selectWindow"));
}
std::vector<std::string> windows;
GetWindowList(windows);
@@ -157,12 +187,14 @@ void AdvSceneSwitcher::populateWindowSelection(QComboBox *sel, bool addSelect)
void AdvSceneSwitcher::populateAudioSelection(QComboBox *sel, bool addSelect)
{
if (addSelect)
if (addSelect) {
addSelectionEntry(
sel,
obs_module_text("AdvSceneSwitcher.selectAudioSource"),
false,
obs_module_text(
"AdvSceneSwitcher.invaildEntriesWillNotBeSaved"));
}
auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */
{
@@ -184,14 +216,52 @@ void AdvSceneSwitcher::populateAudioSelection(QComboBox *sel, bool addSelect)
}
}
void AdvSceneSwitcher::populateVideoSelection(QComboBox *sel, bool addScenes,
bool addSelect)
{
if (addSelect) {
addSelectionEntry(
sel,
obs_module_text("AdvSceneSwitcher.selectVideoSource"),
false,
obs_module_text(
"AdvSceneSwitcher.invaildEntriesWillNotBeSaved"));
}
auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */
{
std::vector<std::string> *list =
reinterpret_cast<std::vector<std::string> *>(data);
uint32_t flags = obs_source_get_output_flags(source);
std::string test = obs_source_get_name(source);
if ((flags & (OBS_SOURCE_VIDEO | OBS_SOURCE_ASYNC)) != 0) {
list->push_back(obs_source_get_name(source));
}
return true;
};
std::vector<std::string> videoSources;
obs_enum_sources(sourceEnum, &videoSources);
sort(videoSources.begin(), videoSources.end());
for (std::string &source : videoSources) {
sel->addItem(source.c_str());
}
if (addScenes) {
populateSceneSelection(sel, false, false, false);
}
}
void AdvSceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect)
{
if (addSelect)
if (addSelect) {
addSelectionEntry(
sel,
obs_module_text("AdvSceneSwitcher.selectMediaSource"),
false,
obs_module_text(
"AdvSceneSwitcher.invaildEntriesWillNotBeSaved"));
}
auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */
{
@@ -215,9 +285,10 @@ void AdvSceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect)
void AdvSceneSwitcher::populateProcessSelection(QComboBox *sel, bool addSelect)
{
if (addSelect)
if (addSelect) {
addSelectionEntry(
sel, obs_module_text("AdvSceneSwitcher.selectProcess"));
}
QStringList processes;
GetProcessList(processes);
@@ -237,8 +308,9 @@ void AdvSceneSwitcher::listAddClicked(QListWidget *list,
return;
}
if (addButton && addHighlight)
if (addButton && addHighlight) {
addButton->disconnect(*addHighlight);
}
QListWidgetItem *item;
item = new QListWidgetItem(list);
@@ -252,8 +324,9 @@ void AdvSceneSwitcher::listAddClicked(QListWidget *list,
bool AdvSceneSwitcher::listMoveUp(QListWidget *list)
{
int index = list->currentRow();
if (index == -1 || index == 0)
if (index == -1 || index == 0) {
return false;
}
QWidget *row = list->itemWidget(list->currentItem());
QListWidgetItem *itemN = list->currentItem()->clone();
@@ -269,8 +342,9 @@ bool AdvSceneSwitcher::listMoveUp(QListWidget *list)
bool AdvSceneSwitcher::listMoveDown(QListWidget *list)
{
int index = list->currentRow();
if (index == -1 || index == list->count() - 1)
if (index == -1 || index == list->count() - 1) {
return false;
}
QWidget *row = list->itemWidget(list->currentItem());
QListWidgetItem *itemN = list->currentItem()->clone();
@@ -288,8 +362,9 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget,
QColor startColor,
QString specifier)
{
if (switcher->disableHints)
if (switcher->disableHints) {
return QMetaObject::Connection();
}
widget->setStyleSheet(specifier + "{ \
border-style: outset; \
@@ -305,7 +380,7 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget,
paAnimation->setStartValue(startColor);
paAnimation->setEndValue(endColor);
paAnimation->setDuration(1000);
// play backward to return to original state on timer end
// Play backwards to return to original state on timer end
paAnimation->setDirection(QAbstractAnimation::Backward);
auto con = QWidget::connect(
@@ -320,9 +395,9 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget,
return con;
}
/********************************************************************************
/******************************************************************************
* Saving and loading
********************************************************************************/
******************************************************************************/
static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
{
if (saving) {
@@ -332,20 +407,7 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
obs_data_t *obj = obs_data_create();
switcher->saveWindowTitleSwitches(obj);
switcher->saveScreenRegionSwitches(obj);
switcher->savePauseSwitches(obj);
switcher->saveSceneSequenceSwitches(obj);
switcher->saveSceneTransitions(obj);
switcher->saveIdleSwitches(obj);
switcher->saveExecutableSwitches(obj);
switcher->saveRandomSwitches(obj);
switcher->saveFileSwitches(obj);
switcher->saveMediaSwitches(obj);
switcher->saveTimeSwitches(obj);
switcher->saveAudioSwitches(obj);
switcher->saveGeneralSettings(obj);
switcher->saveHotkeys(obj);
switcher->saveSettings(obj);
obs_data_set_obj(save_data, "advanced-scene-switcher", obj);
@@ -356,44 +418,37 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
obs_data_t *obj =
obs_data_get_obj(save_data, "advanced-scene-switcher");
if (!obj)
if (!obj) {
obj = obs_data_create();
}
if (switcher->versionChanged(obj, g_GIT_SHA1)) {
AdvSceneSwitcher::AskBackup(obj);
}
switcher->loadWindowTitleSwitches(obj);
switcher->loadScreenRegionSwitches(obj);
switcher->loadPauseSwitches(obj);
switcher->loadSceneSequenceSwitches(obj);
switcher->loadSceneTransitions(obj);
switcher->loadIdleSwitches(obj);
switcher->loadExecutableSwitches(obj);
switcher->loadRandomSwitches(obj);
switcher->loadFileSwitches(obj);
switcher->loadMediaSwitches(obj);
switcher->loadTimeSwitches(obj);
switcher->loadAudioSwitches(obj);
switcher->loadGeneralSettings(obj);
switcher->loadHotkeys(obj);
switcher->loadSettings(obj);
obs_data_release(obj);
switcher->m.unlock();
// stop the scene switcher at least once
// to avoid issues with scene collection changes
// Stop the scene switcher at least once to
// avoid scene duplication issues with scene collection changes
bool start = !switcher->stop;
switcher->Stop();
if (start)
if (start) {
switcher->Start();
}
}
}
/********************************************************************************
/******************************************************************************
* Main switcher thread
********************************************************************************/
******************************************************************************/
void SwitcherData::Thread()
{
blog(LOG_INFO, "started");
int sleep = 0;
int linger = 0;
std::chrono::milliseconds duration;
auto startTime = std::chrono::high_resolution_clock::now();
auto endTime = std::chrono::high_resolution_clock::now();
@@ -404,9 +459,11 @@ void SwitcherData::Thread()
bool match = false;
OBSWeakSource scene;
OBSWeakSource transition;
bool defTransitionMatch = false;
OBSWeakSource defTransition;
// The previous scene might have changed during the linger duration,
// 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();
@@ -417,8 +474,8 @@ void SwitcherData::Thread()
if (sleep) {
duration = std::chrono::milliseconds(sleep);
} else {
duration =
std::chrono::milliseconds(interval) - runTime;
duration = std::chrono::milliseconds(interval) +
std::chrono::milliseconds(linger) - runTime;
if (duration.count() < 1) {
blog(LOG_INFO,
"detected busy loop - refusing to sleep less than 1ms");
@@ -426,82 +483,50 @@ void SwitcherData::Thread()
}
}
//sleep for a bit
if (verbose)
blog(LOG_INFO, "sleep for %ld", duration.count());
vblog(LOG_INFO, "try to sleep for %ld", duration.count());
cv.wait_for(lock, duration);
startTime = std::chrono::high_resolution_clock::now();
sleep = 0;
linger = 0;
switcher->Prune();
if (switcher->stop) {
Prune();
if (stop) {
break;
}
if (autoStopEnable) {
autoStopStreamAndRecording();
}
if (autoStartEnable) {
autoStartStreamRecording();
}
if (checkPause()) {
continue;
}
match = checkForMatch(scene, transition, linger,
setPrevSceneAfterLinger, macroMatch);
if (stop) {
break;
}
checkNoMatchSwitch(match, scene, transition, sleep);
checkSwitchCooldown(match);
checkDefaultSceneTransitions(defTransitionMatch, defTransition);
if (linger) {
duration = std::chrono::milliseconds(linger);
vblog(LOG_INFO, "sleep for %ld before switching scene",
duration.count());
for (int switchFuncName : functionNamesByPriority) {
switch (switchFuncName) {
case read_file_func:
checkSwitchInfoFromFile(match, scene,
transition);
checkFileContent(match, scene, transition);
break;
case idle_func:
checkIdleSwitch(match, scene, transition);
break;
case exe_func:
checkExeSwitch(match, scene, transition);
break;
case screen_region_func:
checkScreenRegionSwitch(match, scene,
transition);
break;
case window_title_func:
checkWindowTitleSwitch(match, scene,
transition);
break;
case round_trip_func:
checkSceneSequence(match, scene, transition,
lock);
break;
case media_func:
checkMediaSwitch(match, scene, transition);
break;
case time_func:
checkTimeSwitch(match, scene, transition);
break;
case audio_func:
checkAudioSwitch(match, scene, transition);
cv.wait_for(lock, duration);
if (stop) {
break;
}
if (switcher->stop) {
goto endLoop;
}
if (match) {
break;
if (sceneChangedDuringWait()) {
vblog(LOG_INFO,
"scene was changed manually - ignoring match");
match = false;
linger = 0;
} else if (setPrevSceneAfterLinger) {
scene = previousScene;
}
}
checkNoMatchSwitch(match, scene, transition, sleep);
checkSwitchCooldown(match);
// After this point we will call frontend functions
// obs_frontend_set_current_scene() and
// obs_frontend_set_current_transition()
@@ -510,37 +535,114 @@ void SwitcherData::Thread()
// leading to a deadlock, so we have to unlock()
lock.unlock();
if (!match && defTransitionMatch) {
setCurrentDefTransition(defTransition);
}
if (match) {
switchScene(scene, transition,
tansitionOverrideOverride);
if (macroMatch) {
runMacros();
} else {
switchScene({scene, transition, 0});
}
}
writeSceneInfoToFile();
}
endLoop:
blog(LOG_INFO, "stopped");
}
void switchScene(OBSWeakSource &scene, OBSWeakSource &transition,
bool &transitionOverrideOverride)
bool SwitcherData::checkForMatch(OBSWeakSource &scene,
OBSWeakSource &transition, int &linger,
bool &setPrevSceneAfterLinger,
bool &macroMatch)
{
obs_source_t *source = obs_weak_source_get_source(scene);
bool match = false;
if (uninterruptibleSceneSequenceActive) {
match = checkSceneSequence(scene, transition, linger,
setPrevSceneAfterLinger);
if (match) {
return match;
}
}
for (int switchFuncName : functionNamesByPriority) {
switch (switchFuncName) {
case read_file_func:
match = checkSwitchInfoFromFile(scene, transition) ||
checkFileContent(scene, transition);
break;
case idle_func:
match = checkIdleSwitch(scene, transition);
break;
case exe_func:
match = checkExeSwitch(scene, transition);
break;
case screen_region_func:
match = checkScreenRegionSwitch(scene, transition);
break;
case window_title_func:
match = checkWindowTitleSwitch(scene, transition);
break;
case round_trip_func:
match = checkSceneSequence(scene, transition, linger,
setPrevSceneAfterLinger);
break;
case media_func:
match = checkMediaSwitch(scene, transition);
break;
case time_func:
match = checkTimeSwitch(scene, transition);
break;
case audio_func:
match = checkAudioSwitch(scene, transition);
break;
case video_func:
match = checkVideoSwitch(scene, transition);
break;
case macro_func:
if (checkMacros()) {
match = true;
macroMatch = true;
}
break;
}
if (stop) {
return false;
}
if (match) {
break;
}
}
return match;
}
void switchScene(sceneSwitchInfo sceneSwitch)
{
if (!sceneSwitch.scene && switcher->verbose) {
blog(LOG_INFO, "nothing to switch to");
return;
}
obs_source_t *source = obs_weak_source_get_source(sceneSwitch.scene);
obs_source_t *currentSource = obs_frontend_get_current_scene();
if (source && source != currentSource) {
transitionData td;
setNextTransition(scene, currentSource, transition,
transitionOverrideOverride, td);
transitionData currentTransitionData;
setNextTransition(sceneSwitch, currentSource,
currentTransitionData);
obs_frontend_set_current_scene(source);
if (transitionOverrideOverride)
restoreTransitionOverride(source, td);
if (switcher->transitionOverrideOverride) {
restoreTransitionOverride(source,
currentTransitionData);
}
if (switcher->verbose)
if (switcher->verbose) {
blog(LOG_INFO, "switched scene");
}
if (switcher->networkConfig.ServerEnabled) {
switcher->server.sendMessage(sceneSwitch);
}
}
obs_source_release(currentSource);
obs_source_release(source);
@@ -550,19 +652,27 @@ void SwitcherData::Start()
{
if (!(th && th->isRunning())) {
stop = false;
switcher->th = new SwitcherThread();
switcher->th->start(
(QThread::Priority)switcher->threadPriority);
th = new SwitcherThread();
th->start((QThread::Priority)threadPriority);
// Will be overwritten quickly but might be useful
writeToStatusFile("Advanced Scene Switcher running");
}
if (networkConfig.ServerEnabled) {
server.start(networkConfig.ServerPort,
networkConfig.LockToIPv4);
}
if (networkConfig.ClientEnabled) {
client.connect(networkConfig.GetClientUri());
}
}
void SwitcherData::Stop()
{
if (th && th->isRunning()) {
switcher->stop = true;
stop = true;
transitionCv.notify_one();
cv.notify_one();
th->wait();
@@ -571,25 +681,30 @@ void SwitcherData::Stop()
writeToStatusFile("Advanced Scene Switcher stopped");
}
server.stop();
client.disconnect();
}
bool SwitcherData::sceneChangedDuringWait()
{
obs_source_t *currentSource = obs_frontend_get_current_scene();
if (!currentSource)
if (!currentSource) {
return true;
}
obs_source_release(currentSource);
return (waitScene && currentSource != waitScene);
}
/********************************************************************************
/******************************************************************************
* OBS module setup
********************************************************************************/
******************************************************************************/
extern "C" void FreeSceneSwitcher()
{
if (loaded_curl_lib) {
if (switcher->curl && f_curl_cleanup)
if (switcher->curl && f_curl_cleanup) {
f_curl_cleanup(switcher->curl);
}
delete loaded_curl_lib;
loaded_curl_lib = nullptr;
}
@@ -600,27 +715,28 @@ extern "C" void FreeSceneSwitcher()
void handleSceneChange(SwitcherData *s)
{
//stop waiting if scene was manually changed
if (s->sceneChangedDuringWait())
// Stop waiting if scene was changed
if (s->sceneChangedDuringWait()) {
s->cv.notify_one();
}
//set previous scene
// Set previous scene
obs_source_t *source = obs_frontend_get_current_scene();
obs_weak_source_t *ws = obs_source_get_weak_source(source);
obs_source_release(source);
obs_weak_source_release(ws);
if (source && s->previousScene2 != ws) {
s->previousScene = s->previousScene2;
s->previousScene2 = ws;
if (source && s->previousSceneHelper != ws) {
s->previousScene = s->previousSceneHelper;
s->previousSceneHelper = ws;
}
//reset events only hanled on scene change
s->autoStartedRecently = false;
}
s->checkTriggers();
s->checkDefaultSceneTransitions();
void handleTransitionStop(SwitcherData *s)
{
s->checkedDefTransition = false;
if (switcher->networkConfig.ServerEnabled &&
switcher->networkConfig.SendAll) {
switcher->server.sendMessage({ws, nullptr, 0});
}
}
void setLiveTime(SwitcherData *s)
@@ -633,6 +749,20 @@ void resetLiveTime(SwitcherData *s)
s->liveTime = QDateTime();
}
void checkAutoStartRecording(SwitcherData *s)
{
if (s->autoStartEvent == AutoStartEvent::RECORDING ||
s->autoStartEvent == AutoStartEvent::RECORINDG_OR_STREAMING)
s->Start();
}
void checkAutoStartStreaming(SwitcherData *s)
{
if (s->autoStartEvent == AutoStartEvent::STREAMING ||
s->autoStartEvent == AutoStartEvent::RECORINDG_OR_STREAMING)
s->Start();
}
// Note to future self:
// be careful using switcher->m here as there is potential for deadlocks when using
// frontend functions such as obs_frontend_set_current_scene()
@@ -645,12 +775,13 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher)
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
handleSceneChange((SwitcherData *)switcher);
break;
case OBS_FRONTEND_EVENT_TRANSITION_STOPPED:
handleTransitionStop((SwitcherData *)switcher);
break;
case OBS_FRONTEND_EVENT_RECORDING_STARTED:
setLiveTime((SwitcherData *)switcher);
checkAutoStartRecording((SwitcherData *)switcher);
break;
case OBS_FRONTEND_EVENT_STREAMING_STARTED:
setLiveTime((SwitcherData *)switcher);
checkAutoStartStreaming((SwitcherData *)switcher);
break;
case OBS_FRONTEND_EVENT_RECORDING_STOPPED:
case OBS_FRONTEND_EVENT_STREAMING_STOPPED:

View File

@@ -54,9 +54,9 @@ bool loadCurl()
libFilePath.toUtf8().constData());
loaded_curl_lib = new QLibrary(libFilePath, nullptr);
if (resolveCurl())
if (resolveCurl()) {
return true;
else {
} else {
delete loaded_curl_lib;
loaded_curl_lib = nullptr;
}

139
src/duration-control.cpp Normal file
View File

@@ -0,0 +1,139 @@
#include "headers/duration-control.hpp"
#include "obs-module.h"
#include <sstream>
#include <iomanip>
#include <QHBoxLayout>
void Duration::Save(obs_data_t *obj, const char *secondsName,
const char *unitName)
{
obs_data_set_double(obj, secondsName, seconds);
obs_data_set_int(obj, unitName, static_cast<int>(displayUnit));
}
void Duration::Load(obs_data_t *obj, const char *secondsName,
const char *unitName)
{
seconds = obs_data_get_double(obj, secondsName);
displayUnit =
static_cast<DurationUnit>(obs_data_get_int(obj, unitName));
}
bool Duration::DurationReached()
{
if (_startTime.time_since_epoch().count() == 0) {
_startTime = std::chrono::high_resolution_clock::now();
}
auto runTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - _startTime);
return runTime.count() >= seconds * 1000;
}
void Duration::Reset()
{
_startTime = {};
}
int durationUnitToMultiplier(DurationUnit u)
{
switch (u) {
case DurationUnit::SECONDS:
return 1;
case DurationUnit::MINUTES:
return 60;
case DurationUnit::HOURS:
return 3600;
default:
break;
}
return 0;
}
std::string durationUnitToString(DurationUnit u)
{
switch (u) {
case DurationUnit::SECONDS:
return obs_module_text("AdvSceneSwitcher.unit.secends");
case DurationUnit::MINUTES:
return obs_module_text("AdvSceneSwitcher.unit.minutes");
case DurationUnit::HOURS:
return obs_module_text("AdvSceneSwitcher.unit.hours");
default:
break;
}
return "";
}
std::string Duration::ToString()
{
std::ostringstream ss;
ss << std::fixed << std::setprecision(2)
<< seconds / durationUnitToMultiplier(displayUnit) << " "
<< durationUnitToString(displayUnit);
return ss.str();
}
static void populateUnits(QComboBox *list)
{
list->addItem(obs_module_text("AdvSceneSwitcher.unit.secends"));
list->addItem(obs_module_text("AdvSceneSwitcher.unit.minutes"));
list->addItem(obs_module_text("AdvSceneSwitcher.unit.hours"));
}
DurationSelection::DurationSelection(QWidget *parent, bool showUnitSelection)
: QWidget(parent), _unitMultiplier(1)
{
_duration = new QDoubleSpinBox(parent);
_duration->setMaximum(86400); // 24 hours
_unitSelection = new QComboBox();
populateUnits(_unitSelection);
QWidget::connect(_duration, SIGNAL(valueChanged(double)), this,
SLOT(_DurationChanged(double)));
QWidget::connect(_unitSelection, SIGNAL(currentIndexChanged(int)), this,
SLOT(_UnitChanged(int)));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(_duration);
if (showUnitSelection) {
layout->addWidget(_unitSelection);
}
setLayout(layout);
}
void DurationSelection::SetValue(double value)
{
_duration->setValue(value / _unitMultiplier);
}
void DurationSelection::SetUnit(DurationUnit u)
{
_unitSelection->setCurrentIndex(static_cast<int>(u));
}
void DurationSelection::SetDuration(Duration d)
{
SetUnit(d.displayUnit);
SetValue(d.seconds);
}
void DurationSelection::_DurationChanged(double value)
{
emit DurationChanged(value * _unitMultiplier);
}
void DurationSelection::_UnitChanged(int idx)
{
DurationUnit unit = static_cast<DurationUnit>(idx);
double prevMultiplier = _unitMultiplier;
_unitMultiplier = durationUnitToMultiplier(unit);
_duration->setValue(_duration->value() *
(prevMultiplier / _unitMultiplier));
emit UnitChanged(unit);
}

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,10 @@
#include "switcher-data-structs.hpp"
#define blog(level, msg, ...) blog(level, "[adv-ss] " msg, ##__VA_ARGS__)
#define vblog(level, msg, ...) \
if (switcher->verbose) { \
blog(level, msg, ##__VA_ARGS__); \
}
class QCloseEvent;
@@ -19,6 +23,7 @@ class AdvSceneSwitcher : public QDialog {
public:
std::unique_ptr<Ui_AdvSceneSwitcher> ui;
bool loading = true;
bool currentStatusActive = false;
AdvSceneSwitcher(QWidget *parent);
@@ -35,10 +40,12 @@ public:
int IgnoreIdleWindowsFindByData(const QString &window);
void UpdateNonMatchingScene(const QString &name);
void UpdateAutoStopScene(const QString &name);
void UpdateAutoStartScene(const QString &name);
void UpdateIdleDataTransition(const QString &name);
void UpdateIdleDataScene(const QString &name);
void OpenSequenceExtendEdit(SequenceWidget *sw);
void SetEditSceneGroup(SceneGroup &sg);
bool addNewMacro(std::string &name);
Macro *getSelectedMacro();
void SetEditMacro(Macro &m);
void loadUI();
void setupGeneralTab();
@@ -54,18 +61,37 @@ public:
void setupFileTab();
void setupTimeTab();
void setupAudioTab();
void setupSceneGroupTab();
void setupTriggerTab();
void setupVideoTab();
void setupNetworkTab();
void setupMacroTab();
void setTabOrder();
void restoreWindowGeo();
void DisplayMessage(QString msg);
static void AskBackup(obs_data_t *obj);
static void addSelectionEntry(QComboBox *sel, const char *description,
bool selectable = false,
const char *tooltip = "");
static void populateSceneSelection(QComboBox *sel,
bool addPrevious = false,
bool addSelect = true);
bool addSceneGroup = false,
bool addSelect = true,
std::string selectText = "",
bool selectable = false);
static void populateTransitionSelection(QComboBox *sel,
bool addSelect = true);
bool addCurrent = true,
bool addSelect = true,
bool selectable = false);
static void populateWindowSelection(QComboBox *sel,
bool addSelect = true);
static void populateAudioSelection(QComboBox *sel,
bool addSelect = true);
static void populateVideoSelection(QComboBox *sel,
bool addScenes = true,
bool addSelect = true);
static void populateMediaSelection(QComboBox *sel,
bool addSelect = true);
static void populateProcessSelection(QComboBox *sel,
@@ -80,6 +106,11 @@ public:
bool listMoveUp(QListWidget *list);
bool listMoveDown(QListWidget *list);
signals:
void SceneGroupAdded(const QString &name);
void SceneGroupRemoved(const QString &name);
void SceneGroupRenamed(const QString &oldName, const QString newName);
public slots:
void on_windowUp_clicked();
void on_windowDown_clicked();
@@ -88,15 +119,31 @@ public slots:
void on_noMatchDontSwitch_clicked();
void on_noMatchSwitch_clicked();
void on_noMatchRandomSwitch_clicked();
void on_noMatchDelay_valueChanged(double i);
void on_cooldownTime_valueChanged(double i);
void NoMatchDelayDurationChanged(double);
void NoMatchDelayUnitChanged(DurationUnit);
void CooldownDurationChanged(double);
void CooldownUnitChanged(DurationUnit);
void on_startupBehavior_currentIndexChanged(int index);
void on_autoStartEvent_currentIndexChanged(int index);
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
void on_checkInterval_valueChanged(int value);
void on_toggleStartButton_clicked();
void on_tabMoved(int from, int to);
void on_tabWidget_currentChanged(int index);
void on_macroAdd_clicked();
void on_macroRemove_clicked();
void on_macroUp_clicked();
void on_macroDown_clicked();
void on_macroName_editingFinished();
void on_macros_currentRowChanged(int idx);
void on_conditionAdd_clicked();
void on_conditionRemove_clicked();
void on_actionAdd_clicked();
void on_actionRemove_clicked();
void showMacroContextMenu(const QPoint &);
void copyMacro();
void on_screenRegionSwitches_currentRowChanged(int idx);
void on_showFrame_clicked();
void on_screenRegionAdd_clicked();
@@ -115,19 +162,15 @@ public slots:
void on_sceneSequenceAdd_clicked();
void on_sceneSequenceRemove_clicked();
void on_sceneSequenceSave_clicked();
void on_sceneSequenceLoad_clicked();
void on_sceneSequenceUp_clicked();
void on_sceneSequenceDown_clicked();
void on_autoStopSceneCheckBox_stateChanged(int state);
void on_autoStopScenes_currentTextChanged(const QString &text);
void on_autoStartSceneCheckBox_stateChanged(int state);
void on_autoStartType_currentIndexChanged(int index);
void on_autoStartScenes_currentTextChanged(const QString &text);
void on_sceneSequenceSave_clicked();
void on_sceneSequenceLoad_clicked();
void on_sequenceEdit_clicked();
void on_sceneSequenceSwitches_itemDoubleClicked(QListWidgetItem *item);
void on_verboseLogging_stateChanged(int state);
void on_saveWindowGeo_stateChanged(int state);
void on_uiHintsDisable_stateChanged(int state);
void on_exportSettings_clicked();
@@ -142,6 +185,8 @@ public slots:
void on_defaultTransitionsUp_clicked();
void on_defaultTransitionsDown_clicked();
void on_transitionOverridecheckBox_stateChanged(int state);
void on_adjustActiveTransitionType_stateChanged(int state);
void defTransitionDelayValueChanged(int value);
void on_browseButton_clicked();
void on_readFileCheckBox_stateChanged(int state);
@@ -155,9 +200,6 @@ public slots:
void on_executableRemove_clicked();
void on_idleCheckBox_stateChanged(int state);
void on_idleTransitions_currentTextChanged(const QString &text);
void on_idleScenes_currentTextChanged(const QString &text);
void on_idleSpinBox_valueChanged(int i);
void on_ignoreIdleWindows_currentRowChanged(int idx);
void on_ignoreIdleAdd_clicked();
void on_ignoreIdleRemove_clicked();
@@ -187,57 +229,90 @@ public slots:
void on_audioDown_clicked();
void on_audioFallback_toggled(bool on);
void on_videoAdd_clicked();
void on_videoRemove_clicked();
void on_videoUp_clicked();
void on_videoDown_clicked();
void on_getScreenshot_clicked();
void on_serverSettings_toggled(bool on);
void on_serverPort_valueChanged(int value);
void on_lockToIPv4_stateChanged(int state);
void on_serverRestart_clicked();
void updateServerStatus();
void on_clientSettings_toggled(bool on);
void on_clientHostname_textChanged(const QString &text);
void on_clientPort_valueChanged(int value);
void on_restrictSend_stateChanged(int state);
void on_clientReconnect_clicked();
void updateClientStatus();
void on_sceneGroupAdd_clicked();
void on_sceneGroupRemove_clicked();
void on_sceneGroupUp_clicked();
void on_sceneGroupDown_clicked();
void on_sceneGroupName_editingFinished();
void on_sceneGroups_currentRowChanged(int idx);
void on_sceneGroupSceneAdd_clicked();
void on_sceneGroupSceneRemove_clicked();
void on_sceneGroupSceneUp_clicked();
void on_sceneGroupSceneDown_clicked();
void on_triggerAdd_clicked();
void on_triggerRemove_clicked();
void on_triggerUp_clicked();
void on_triggerDown_clicked();
void on_priorityUp_clicked();
void on_priorityDown_clicked();
void on_threadPriority_currentTextChanged(const QString &text);
void updateScreenRegionCursorPos();
void updateStatus();
void on_close_clicked();
private:
};
/********************************************************************************
/******************************************************************************
* Windowtitle helper
********************************************************************************/
******************************************************************************/
void GetWindowList(std::vector<std::string> &windows);
void GetWindowList(QStringList &windows); // Overloaded
void GetWindowList(QStringList &windows);
void GetCurrentWindowTitle(std::string &title);
bool isFullscreen(std::string &title);
bool isMaximized(std::string &title);
/********************************************************************************
/******************************************************************************
* Screenregion helper
********************************************************************************/
******************************************************************************/
std::pair<int, int> getCursorPos();
/********************************************************************************
/******************************************************************************
* Idle detection helper
********************************************************************************/
******************************************************************************/
int secondsSinceLastInput();
/********************************************************************************
/******************************************************************************
* Executable helper
********************************************************************************/
******************************************************************************/
void GetProcessList(QStringList &processes);
bool isInFocus(const QString &executable);
/********************************************************************************
/******************************************************************************
* Sceneswitch helper
********************************************************************************/
******************************************************************************/
void setNextTransition(OBSWeakSource &targetScene, obs_source_t *currentSource,
OBSWeakSource &transition,
bool &transitionOverrideOverride, transitionData &td);
void overwriteTransitionOverride(obs_weak_source_t *sceneWs,
obs_source_t *transition, transitionData &td);
void setNextTransition(sceneSwitchInfo &ssi, obs_source_t *currentSource,
transitionData &td);
void overwriteTransitionOverride(sceneSwitchInfo ssi, transitionData &td);
void restoreTransitionOverride(obs_source_t *scene, transitionData td);
void switchScene(OBSWeakSource &scene, OBSWeakSource &transition,
bool &transitionOverrideOverride);
void switchScene(sceneSwitchInfo ssi);
/********************************************************************************
/******************************************************************************
* Main SwitcherData
********************************************************************************/
******************************************************************************/
struct SwitcherData;
extern SwitcherData *switcher;

View File

@@ -0,0 +1,55 @@
#pragma once
#include <QWidget>
#include <QDoubleSpinBox>
#include <QComboBox>
#include <chrono>
#include "obs-data.h"
enum class DurationUnit {
SECONDS,
MINUTES,
HOURS,
};
class Duration {
public:
void Save(obs_data_t *obj, const char *secondsName = "seconds",
const char *unitName = "displayUnit");
void Load(obs_data_t *obj, const char *secondsName = "seconds",
const char *unitName = "displayUnit");
bool DurationReached();
void Reset();
std::string ToString();
double seconds = 0.;
// only used for UI
DurationUnit displayUnit = DurationUnit::SECONDS;
private:
std::chrono::high_resolution_clock::time_point _startTime;
};
class DurationSelection : public QWidget {
Q_OBJECT
public:
DurationSelection(QWidget *parent = nullptr,
bool showUnitSelection = true);
void SetValue(double value);
void SetUnit(DurationUnit u);
void SetDuration(Duration d);
private slots:
void _DurationChanged(double value);
void _UnitChanged(int idx);
signals:
void DurationChanged(double value); // always reutrn value in seconds
void UnitChanged(DurationUnit u);
private:
QDoubleSpinBox *_duration;
QComboBox *_unitSelection;
double _unitMultiplier;
};

View File

@@ -0,0 +1,63 @@
#pragma once
#include <QSpinBox>
#include "macro-action-edit.hpp"
enum class AudioAction {
MUTE,
UNMUTE,
SOURCE_VOLUME,
MASTER_VOLUME,
};
class MacroActionAudio : public MacroAction {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionAudio>();
}
OBSWeakSource _audioSource;
AudioAction _action = AudioAction::MUTE;
int _volume = 0;
private:
static bool _registered;
static const int id;
};
class MacroActionAudioEdit : public QWidget {
Q_OBJECT
public:
MacroActionAudioEdit(
QWidget *parent,
std::shared_ptr<MacroActionAudio> entryData = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionAudioEdit(
parent,
std::dynamic_pointer_cast<MacroActionAudio>(action));
}
private slots:
void SourceChanged(const QString &text);
void ActionChanged(int value);
void VolumeChanged(int value);
protected:
QComboBox *_audioSources;
QComboBox *_actions;
QSpinBox *_volumePercent;
std::shared_ptr<MacroActionAudio> _entryData;
private:
QHBoxLayout *_mainLayout;
bool _loading = true;
};

View File

@@ -0,0 +1,54 @@
#pragma once
#include <QWidget>
#include <QComboBox>
#include <QVBoxLayout>
#include <QGroupBox>
#include <deque>
#include "macro.hpp"
#include "section.hpp"
struct MacroActionInfo {
using TCreateMethod = std::shared_ptr<MacroAction> (*)();
using TCreateWidgetMethod = QWidget *(*)(QWidget *parent,
std::shared_ptr<MacroAction>);
TCreateMethod _createFunc;
TCreateWidgetMethod _createWidgetFunc;
std::string _name;
};
class MacroActionFactory {
public:
MacroActionFactory() = delete;
static bool Register(int id, MacroActionInfo);
static std::shared_ptr<MacroAction> Create(const int id);
static QWidget *CreateWidget(const int id, QWidget *parent,
std::shared_ptr<MacroAction> action);
static auto GetActionTypes() { return _methods; }
private:
static std::map<int, MacroActionInfo> _methods;
};
class MacroActionEdit : public QWidget {
Q_OBJECT
public:
MacroActionEdit(QWidget *parent = nullptr,
std::shared_ptr<MacroAction> * = nullptr, int type = 0,
bool startCollapsed = false);
void UpdateEntryData(int type);
void Collapse(bool collapsed);
private slots:
void ActionSelectionChanged(int idx);
protected:
QComboBox *_actionSelection;
Section *_section;
std::shared_ptr<MacroAction> *_entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,59 @@
#pragma once
#include <QDoubleSpinBox>
#include <QLabel>
#include "macro-action-edit.hpp"
enum class RecordAction {
STOP,
START,
PAUSE,
UNPAUSE,
};
class MacroActionRecord : public MacroAction {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionRecord>();
}
RecordAction _action = RecordAction::STOP;
private:
static bool _registered;
static const int id;
};
class MacroActionRecordEdit : public QWidget {
Q_OBJECT
public:
MacroActionRecordEdit(
QWidget *parent,
std::shared_ptr<MacroActionRecord> entryData = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionRecordEdit(
parent,
std::dynamic_pointer_cast<MacroActionRecord>(action));
}
private slots:
void ActionChanged(int value);
protected:
QComboBox *_actions;
QLabel *_pauseHint;
std::shared_ptr<MacroActionRecord> _entryData;
private:
QHBoxLayout *_mainLayout;
bool _loading = true;
};

View File

@@ -0,0 +1,66 @@
#pragma once
#include <QDoubleSpinBox>
#include "macro-action-edit.hpp"
#include "duration-control.hpp"
enum class ReplayBufferAction {
STOP,
START,
SAVE,
};
class MacroActionReplayBuffer : public MacroAction {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionReplayBuffer>();
}
ReplayBufferAction _action = ReplayBufferAction::STOP;
private:
// Add artifical delay before trying to save the replay buffer again.
//
// Continiously calling obs_frontend_replay_buffer_save() does not
// result in any output actually being written.
// OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED also seems to be sent before
// any data is written.
Duration _duration;
static bool _registered;
static const int id;
};
class MacroActionReplayBufferEdit : public QWidget {
Q_OBJECT
public:
MacroActionReplayBufferEdit(
QWidget *parent,
std::shared_ptr<MacroActionReplayBuffer> entryData = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionReplayBufferEdit(
parent,
std::dynamic_pointer_cast<MacroActionReplayBuffer>(
action));
}
private slots:
void ActionChanged(int value);
protected:
QComboBox *_actions;
std::shared_ptr<MacroActionReplayBuffer> _entryData;
private:
QHBoxLayout *_mainLayout;
bool _loading = true;
};

View File

@@ -0,0 +1,52 @@
#pragma once
#include "macro-action-edit.hpp"
#include <QLineEdit>
#include <QPushButton>
class MacroActionRun : public MacroAction {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionRun>();
}
std::string _path = obs_module_text("AdvSceneSwitcher.enterPath");
private:
static bool _registered;
static const int id;
};
class MacroActionRunEdit : public QWidget {
Q_OBJECT
public:
MacroActionRunEdit(QWidget *parent,
std::shared_ptr<MacroActionRun> entryData = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionRunEdit(
parent,
std::dynamic_pointer_cast<MacroActionRun>(action));
}
private slots:
void FilePathChanged();
void BrowseButtonClicked();
protected:
std::shared_ptr<MacroActionRun> _entryData;
private:
QLineEdit *_filePath;
QPushButton *_browseButton;
bool _loading = true;
};

View File

@@ -0,0 +1,60 @@
#pragma once
#include <QDoubleSpinBox>
#include "macro-action-edit.hpp"
#include "duration-control.hpp"
enum class StreamAction {
STOP,
START,
};
class MacroActionStream : public MacroAction {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionStream>();
}
StreamAction _action = StreamAction::STOP;
private:
// Acts as a safeguard for misconfigured streaming setups leading to an
// endless error spam.
Duration _retryCooldown;
static bool _registered;
static const int id;
};
class MacroActionStreamEdit : public QWidget {
Q_OBJECT
public:
MacroActionStreamEdit(
QWidget *parent,
std::shared_ptr<MacroActionStream> entryData = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionStreamEdit(
parent,
std::dynamic_pointer_cast<MacroActionStream>(action));
}
private slots:
void ActionChanged(int value);
protected:
QComboBox *_actions;
std::shared_ptr<MacroActionStream> _entryData;
private:
QHBoxLayout *_mainLayout;
bool _loading = true;
};

View File

@@ -0,0 +1,49 @@
#pragma once
#include "macro-action-edit.hpp"
#include "switch-generic.hpp"
#include "duration-control.hpp"
class MacroActionSwitchScene : public MacroAction, public SceneSwitcherEntry {
public:
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionSwitchScene>();
}
Duration _duration;
private:
const char *getType() { return "MacroActionSwitchScene"; }
static bool _registered;
static const int id;
};
class MacroActionSwitchSceneEdit : public SwitchWidget {
Q_OBJECT
public:
MacroActionSwitchSceneEdit(
QWidget *parent,
std::shared_ptr<MacroActionSwitchScene> entryData = nullptr);
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionSwitchSceneEdit(
parent,
std::dynamic_pointer_cast<MacroActionSwitchScene>(
action));
}
private slots:
void DurationChanged(double seconds);
protected:
DurationSelection *_duration;
std::shared_ptr<MacroActionSwitchScene> _entryData;
};

View File

@@ -0,0 +1,64 @@
#pragma once
#include <QDoubleSpinBox>
#include "macro-action-edit.hpp"
#include "duration-control.hpp"
enum class WaitType {
FIXED,
RANDOM,
};
class MacroActionWait : public MacroAction {
public:
bool PerformAction();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroAction> Create()
{
return std::make_shared<MacroActionWait>();
}
Duration _duration;
Duration _duration2;
WaitType _waitType = WaitType::FIXED;
private:
static bool _registered;
static const int id;
};
class MacroActionWaitEdit : public QWidget {
Q_OBJECT
public:
MacroActionWaitEdit(
QWidget *parent,
std::shared_ptr<MacroActionWait> entryData = nullptr);
void UpdateEntryData();
void SetupFixedDurationEdit();
void SetupRandomDurationEdit();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroAction> action)
{
return new MacroActionWaitEdit(
parent,
std::dynamic_pointer_cast<MacroActionWait>(action));
}
private slots:
void DurationChanged(double value);
void DurationUnitChanged(DurationUnit unit);
void Duration2Changed(double value);
void Duration2UnitChanged(DurationUnit unit);
void TypeChanged(int value);
protected:
DurationSelection *_duration;
DurationSelection *_duration2;
QComboBox *_waitType;
std::shared_ptr<MacroActionWait> _entryData;
private:
QHBoxLayout *_mainLayout;
bool _loading = true;
};

View File

@@ -0,0 +1,78 @@
#pragma once
#include "macro.hpp"
#include "volume-control.hpp"
#include <limits>
#include <QWidget>
#include <QComboBox>
#include <chrono>
#include "duration-control.hpp"
enum class AudioCondition {
ABOVE,
BELOW,
};
class MacroConditionAudio : public MacroCondition {
public:
~MacroConditionAudio();
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionAudio>();
}
static void SetVolumeLevel(void *data,
const float magnitude[MAX_AUDIO_CHANNELS],
const float peak[MAX_AUDIO_CHANNELS],
const float inputPeak[MAX_AUDIO_CHANNELS]);
void ResetVolmeter();
OBSWeakSource _audioSource;
int _volume = 0;
AudioCondition _condition = AudioCondition::ABOVE;
Duration _duration;
obs_volmeter_t *_volmeter = nullptr;
private:
float _peak = -std::numeric_limits<float>::infinity();
static bool _registered;
static const int id;
};
class MacroConditionAudioEdit : public QWidget {
Q_OBJECT
public:
MacroConditionAudioEdit(
QWidget *parent,
std::shared_ptr<MacroConditionAudio> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionAudioEdit(
parent,
std::dynamic_pointer_cast<MacroConditionAudio>(cond));
}
void UpdateVolmeterSource();
private slots:
void SourceChanged(const QString &text);
void VolumeThresholdChanged(int vol);
void ConditionChanged(int cond);
void DurationChanged(double seconds);
protected:
QComboBox *_audioSources;
QComboBox *_condition;
QSpinBox *_volume;
DurationSelection *_duration;
VolControl *_volMeter = nullptr;
std::shared_ptr<MacroConditionAudio> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,59 @@
#pragma once
#include "advanced-scene-switcher.hpp"
#include "macro.hpp"
#include "macro-condition-scene.hpp"
#include "section.hpp"
#include "utility.hpp"
#include <QGroupBox>
struct MacroConditionInfo {
using TCreateMethod = std::shared_ptr<MacroCondition> (*)();
using TCreateWidgetMethod =
QWidget *(*)(QWidget *parent, std::shared_ptr<MacroCondition>);
TCreateMethod _createFunc;
TCreateWidgetMethod _createWidgetFunc;
std::string _name;
};
class MacroConditionFactory {
public:
MacroConditionFactory() = delete;
static bool Register(int id, MacroConditionInfo);
static std::shared_ptr<MacroCondition> Create(const int id);
static QWidget *CreateWidget(const int id, QWidget *parent,
std::shared_ptr<MacroCondition>);
static auto GetConditionTypes() { return _methods; }
private:
static std::map<int, MacroConditionInfo> _methods;
};
class MacroConditionEdit : public QWidget {
Q_OBJECT
public:
MacroConditionEdit(QWidget *parent = nullptr,
std::shared_ptr<MacroCondition> * = nullptr,
int type = 0, bool root = true,
bool startCollapsed = false);
bool IsRootNode();
void UpdateEntryData(int type);
void Collapse(bool collapsed);
private slots:
void LogicSelectionChanged(int idx);
void ConditionSelectionChanged(int idx);
protected:
QComboBox *_logicSelection;
QComboBox *_conditionSelection;
Section *_section;
std::shared_ptr<MacroCondition> *_entryData;
private:
bool _isRoot = true;
bool _loading = true;
};

View File

@@ -0,0 +1,82 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include <QDateTime>
#include <QLineEdit>
#include <QPushButton>
#include <QPlainTextEdit>
#include <QCheckBox>
enum class FileType {
LOCAL,
REMOTE,
};
class MacroConditionFile : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionFile>();
}
std::string _file = obs_module_text("AdvSceneSwitcher.enterPath");
std::string _text = obs_module_text("AdvSceneSwitcher.enterText");
FileType _fileType = FileType::LOCAL;
bool _useRegex = false;
bool _useTime = false;
bool _onlyMatchIfChanged = false;
private:
bool matchFileContent(QString &filedata);
bool checkRemoteFileContent();
bool checkLocalFileContent();
QDateTime _lastMod;
size_t _lastHash = 0;
static bool _registered;
static const int id;
};
class MacroConditionFileEdit : public QWidget {
Q_OBJECT
public:
MacroConditionFileEdit(
QWidget *parent,
std::shared_ptr<MacroConditionFile> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionFileEdit(
parent,
std::dynamic_pointer_cast<MacroConditionFile>(cond));
}
private slots:
void FileTypeChanged(int index);
void FilePathChanged();
void BrowseButtonClicked();
void MatchTextChanged();
void UseRegexChanged(int state);
void CheckModificationDateChanged(int state);
void OnlyMatchIfChangedChanged(int state);
protected:
QComboBox *_fileType;
QLineEdit *_filePath;
QPushButton *_browseButton;
QPlainTextEdit *_matchText;
QCheckBox *_useRegex;
QCheckBox *_checkModificationDate;
QCheckBox *_checkFileContent;
std::shared_ptr<MacroConditionFile> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,51 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include "duration-control.hpp"
class MacroConditionIdle : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionIdle>();
}
Duration _duration;
private:
static bool _registered;
static const int id;
};
class MacroConditionIdleEdit : public QWidget {
Q_OBJECT
public:
MacroConditionIdleEdit(
QWidget *parent,
std::shared_ptr<MacroConditionIdle> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionIdleEdit(
parent,
std::dynamic_pointer_cast<MacroConditionIdle>(cond));
}
private slots:
void DurationChanged(double seconds);
void DurationUnitChanged(DurationUnit unit);
protected:
DurationSelection *_duration;
std::shared_ptr<MacroConditionIdle> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,103 @@
#pragma once
#include "macro.hpp"
#include <limits>
#include <QWidget>
#include <QComboBox>
#include "duration-control.hpp"
enum class MediaTimeRestriction {
TIME_RESTRICTION_NONE,
TIME_RESTRICTION_SHORTER,
TIME_RESTRICTION_LONGER,
TIME_RESTRICTION_REMAINING_SHORTER,
TIME_RESTRICTION_REMAINING_LONGER,
};
constexpr auto custom_media_states_offset = 100;
enum class MediaState {
// OBS's internal states
OBS_MEDIA_STATE_NONE,
OBS_MEDIA_STATE_PLAYING,
OBS_MEDIA_STATE_OPENING,
OBS_MEDIA_STATE_BUFFERING,
OBS_MEDIA_STATE_PAUSED,
OBS_MEDIA_STATE_STOPPED,
OBS_MEDIA_STATE_ENDED,
OBS_MEDIA_STATE_ERROR,
// Just a marker
LAST_OBS_MEDIA_STATE,
// states added for use in the plugin
PLAYED_TO_END = custom_media_states_offset,
ANY,
};
class MacroConditionMedia : public MacroCondition {
public:
~MacroConditionMedia();
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionMedia>();
}
void ClearSignalHandler();
void ResetSignalHandler();
static void MediaStopped(void *data, calldata_t *);
static void MediaEnded(void *data, calldata_t *);
OBSWeakSource _source = nullptr;
MediaState _state = MediaState::OBS_MEDIA_STATE_NONE;
MediaTimeRestriction _restriction =
MediaTimeRestriction::TIME_RESTRICTION_NONE;
Duration _time;
private:
std::atomic_bool _stopped = {false};
std::atomic_bool _ended = {false};
// Trigger scene change only once even if media state might trigger repeatedly
bool _alreadyMatched = false;
// Workaround to enable use of "ended" to specify end of VLC playlist
bool _previousStateEnded = false;
bool _playedToEnd = false;
static bool _registered;
static const int id;
};
class MacroConditionMediaEdit : public QWidget {
Q_OBJECT
public:
MacroConditionMediaEdit(
QWidget *parent,
std::shared_ptr<MacroConditionMedia> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionMediaEdit(
parent,
std::dynamic_pointer_cast<MacroConditionMedia>(cond));
}
private slots:
void SourceChanged(const QString &text);
void StateChanged(int index);
void TimeRestrictionChanged(int index);
void TimeChanged(double seconds);
void TimeUnitChanged(DurationUnit unit);
protected:
QComboBox *_mediaSources;
QComboBox *_states;
QComboBox *_timeRestrictions;
DurationSelection *_time;
std::shared_ptr<MacroConditionMedia> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,54 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
enum class PluginStateCondition {
SCENESWITCHED,
};
class MacroConditionPluginState : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionPluginState>();
}
PluginStateCondition _condition = PluginStateCondition::SCENESWITCHED;
private:
static bool _registered;
static const int id;
};
class MacroConditionPluginStateEdit : public QWidget {
Q_OBJECT
public:
MacroConditionPluginStateEdit(
QWidget *parent,
std::shared_ptr<MacroConditionPluginState> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionPluginStateEdit(
parent,
std::dynamic_pointer_cast<MacroConditionPluginState>(
cond));
}
private slots:
void ConditionChanged(int cond);
protected:
QComboBox *_condition;
std::shared_ptr<MacroConditionPluginState> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,52 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
class MacroConditionProcess : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionProcess>();
}
std::string _process;
bool _focus = true;
private:
static bool _registered;
static const int id;
};
class MacroConditionProcessEdit : public QWidget {
Q_OBJECT
public:
MacroConditionProcessEdit(
QWidget *parent,
std::shared_ptr<MacroConditionProcess> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionProcessEdit(
parent,
std::dynamic_pointer_cast<MacroConditionProcess>(cond));
}
private slots:
void ProcessChanged(const QString &text);
void FocusChanged(int state);
protected:
QComboBox *_processSelection;
QCheckBox *_focused;
std::shared_ptr<MacroConditionProcess> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,60 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include "duration-control.hpp"
enum class RecordState {
STOP,
PAUSE,
START,
};
class MacroConditionRecord : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionRecord>();
}
RecordState _recordState;
Duration _duration;
private:
static bool _registered;
static const int id;
};
class MacroConditionRecordEdit : public QWidget {
Q_OBJECT
public:
MacroConditionRecordEdit(
QWidget *parent,
std::shared_ptr<MacroConditionRecord> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionRecordEdit(
parent,
std::dynamic_pointer_cast<MacroConditionRecord>(cond));
}
private slots:
void StateChanged(int value);
void DurationChanged(double seconds);
void DurationUnitChanged(DurationUnit unit);
protected:
QComboBox *_recordState;
DurationSelection *_duration;
std::shared_ptr<MacroConditionRecord> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,55 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
class MacroConditionRegion : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionRegion>();
}
int _minX = 0, _minY = 0, _maxX = 0, _maxY = 0;
private:
static bool _registered;
static const int id;
};
class MacroConditionRegionEdit : public QWidget {
Q_OBJECT
public:
MacroConditionRegionEdit(
QWidget *parent,
std::shared_ptr<MacroConditionRegion> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionRegionEdit(
parent,
std::dynamic_pointer_cast<MacroConditionRegion>(cond));
}
private slots:
void MinXChanged(int pos);
void MinYChanged(int pos);
void MaxXChanged(int pos);
void MaxYChanged(int pos);
protected:
QSpinBox *_minX;
QSpinBox *_minY;
QSpinBox *_maxX;
QSpinBox *_maxY;
std::shared_ptr<MacroConditionRegion> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,62 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include "duration-control.hpp"
enum class SceneType {
CURRENT,
PREVIOUS,
};
class MacroConditionScene : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionScene>();
}
OBSWeakSource _scene;
SceneType _type;
Duration _duration;
private:
static bool _registered;
static const int id;
};
class MacroConditionSceneEdit : public QWidget {
Q_OBJECT
public:
MacroConditionSceneEdit(
QWidget *parent,
std::shared_ptr<MacroConditionScene> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionSceneEdit(
parent,
std::dynamic_pointer_cast<MacroConditionScene>(cond));
}
private slots:
void SceneChanged(const QString &text);
void TypeChanged(int value);
void DurationChanged(double seconds);
void DurationUnitChanged(DurationUnit unit);
protected:
QComboBox *_sceneSelection;
QComboBox *_sceneType;
DurationSelection *_duration;
std::shared_ptr<MacroConditionScene> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,59 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include "duration-control.hpp"
enum class StreamState {
STOP,
START,
};
class MacroConditionStream : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionStream>();
}
StreamState _streamState;
Duration _duration;
private:
static bool _registered;
static const int id;
};
class MacroConditionStreamEdit : public QWidget {
Q_OBJECT
public:
MacroConditionStreamEdit(
QWidget *parent,
std::shared_ptr<MacroConditionStream> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionStreamEdit(
parent,
std::dynamic_pointer_cast<MacroConditionStream>(cond));
}
private slots:
void StateChanged(int value);
void DurationChanged(double seconds);
void DurationUnitChanged(DurationUnit unit);
protected:
QComboBox *_streamState;
DurationSelection *_duration;
std::shared_ptr<MacroConditionStream> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,82 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
#include <chrono>
#include "duration-control.hpp"
#include "screenshot-helper.hpp"
enum class VideoCondition {
MATCH,
DIFFER,
HAS_NOT_CHANGED,
HAS_CHANGED,
NO_IMAGE,
};
class MacroConditionVideo : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
QImage GetMatchImage() { return _matchImage; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionVideo>();
}
void GetScreenshot();
bool LoadImageFromFile();
OBSWeakSource _videoSource;
VideoCondition _condition = VideoCondition::MATCH;
Duration _duration;
std::string _file = obs_module_text("AdvSceneSwitcher.enterPath");
private:
bool Compare();
std::unique_ptr<AdvSSScreenshotObj> _screenshotData = nullptr;
QImage _matchImage;
static bool _registered;
static const int id;
};
class MacroConditionVideoEdit : public QWidget {
Q_OBJECT
public:
MacroConditionVideoEdit(
QWidget *parent,
std::shared_ptr<MacroConditionVideo> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionVideoEdit(
parent,
std::dynamic_pointer_cast<MacroConditionVideo>(cond));
}
void UpdatePreviewTooltip();
void SetFilePath(const QString &text);
private slots:
void SourceChanged(const QString &text);
void ConditionChanged(int cond);
void FilePathChanged();
void BrowseButtonClicked();
void DurationChanged(double seconds);
void DurationUnitChanged(DurationUnit unit);
protected:
QComboBox *_videoSelection;
DurationSelection *_duration;
QComboBox *_condition;
QLineEdit *_filePath;
QPushButton *_browseButton;
std::shared_ptr<MacroConditionVideo> _entryData;
private:
bool _loading = true;
};

View File

@@ -0,0 +1,64 @@
#pragma once
#include "macro.hpp"
#include <QWidget>
#include <QComboBox>
class MacroConditionWindow : public MacroCondition {
public:
bool CheckCondition();
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
int GetId() { return id; };
static std::shared_ptr<MacroCondition> Create()
{
return std::make_shared<MacroConditionWindow>();
}
private:
bool CheckWindowTitleSwitchDirect(std::string &currentWindowTitle);
bool CheckWindowTitleSwitchRegex(std::string &currentWindowTitle,
std::vector<std::string> &windowList);
public:
std::string _window;
bool _fullscreen = false;
bool _maximized = false;
bool _focus = true;
private:
static bool _registered;
static const int id;
};
class MacroConditionWindowEdit : public QWidget {
Q_OBJECT
public:
MacroConditionWindowEdit(
QWidget *parent,
std::shared_ptr<MacroConditionWindow> cond = nullptr);
void UpdateEntryData();
static QWidget *Create(QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
return new MacroConditionWindowEdit(
parent,
std::dynamic_pointer_cast<MacroConditionWindow>(cond));
}
private slots:
void WindowChanged(const QString &text);
void FullscreenChanged(int state);
void MaximizedChanged(int state);
void FocusChanged(int state);
protected:
QComboBox *_windowSelection;
QCheckBox *_fullscreen;
QCheckBox *_maximized;
QCheckBox *_focused;
std::shared_ptr<MacroConditionWindow> _entryData;
private:
bool _loading = true;
};

88
src/headers/macro.hpp Normal file
View File

@@ -0,0 +1,88 @@
#pragma once
#include <string>
#include <deque>
#include <memory>
#include <map>
#include <obs.hpp>
#include <obs-module.h>
constexpr auto macro_func = 10;
constexpr auto default_priority_10 = macro_func;
constexpr auto logic_root_offset = 100;
enum class LogicType {
ROOT_NONE = 0,
ROOT_NOT,
ROOT_LAST,
// leave some space for potential expansion
NONE = 100,
AND,
OR,
AND_NOT,
OR_NOT,
LAST,
};
static inline bool isRootLogicType(LogicType l)
{
return static_cast<int>(l) < logic_root_offset;
}
struct LogicTypeInfo {
std::string _name;
};
class MacroCondition {
public:
virtual bool CheckCondition() = 0;
virtual bool Save(obs_data_t *obj) = 0;
virtual bool Load(obs_data_t *obj) = 0;
virtual int GetId() = 0;
LogicType GetLogicType() { return _logic; }
void SetLogicType(LogicType logic) { _logic = logic; }
static const std::map<LogicType, LogicTypeInfo> logicTypes;
private:
LogicType _logic;
};
class MacroAction {
public:
virtual bool PerformAction() = 0;
virtual bool Save(obs_data_t *obj) = 0;
virtual bool Load(obs_data_t *obj) = 0;
virtual int GetId() = 0;
virtual void LogAction();
};
class Macro {
public:
Macro(std::string name = "");
virtual ~Macro();
bool CeckMatch();
bool PerformAction();
bool Matched() { return _matched; }
std::string Name() { return _name; }
void SetName(std::string name) { _name = name; }
std::deque<std::shared_ptr<MacroCondition>> &Conditions()
{
return _conditions;
}
std::deque<std::shared_ptr<MacroAction>> &Actions() { return _actions; }
bool Save(obs_data_t *obj);
bool Load(obs_data_t *obj);
// Helper function for plugin state condition regarding scene change
bool SwitchesScene();
private:
std::string _name = "";
std::deque<std::shared_ptr<MacroCondition>> _conditions;
std::deque<std::shared_ptr<MacroAction>> _actions;
bool _matched = false;
};

View File

@@ -0,0 +1,24 @@
#pragma once
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
// Based on OBS's NameDialog
class AdvSSNameDialog : public QDialog {
Q_OBJECT
public:
AdvSSNameDialog(QWidget *parent);
// Returns true if user clicks OK, false otherwise
// userTextInput returns string that user typed into dialog
static bool AskForName(QWidget *parent, const QString &title,
const QString &text, std::string &userTextInput,
const QString &placeHolder = QString(""),
int maxSize = 170);
private:
QLabel *label;
QLineEdit *userText;
};

View File

@@ -0,0 +1,84 @@
#pragma once
#include <vector>
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QCheckBox>
#include <obs.hpp>
auto constexpr invalid_scene_group_name = "invalid-scene-group";
enum class AdvanceCondition {
Count,
Time,
Random,
};
struct SceneGroup {
OBSWeakSource getCurrentScene();
OBSWeakSource getNextScene();
OBSWeakSource getNextSceneCount();
OBSWeakSource getNextSceneTime();
OBSWeakSource getNextSceneRandom();
void advanceIdx();
std::string name = invalid_scene_group_name;
AdvanceCondition type = AdvanceCondition::Count;
std::vector<OBSWeakSource> scenes = {};
int count = 1;
double time = 0;
bool repeat = false;
size_t currentIdx = 0;
int currentCount = -1;
std::chrono::high_resolution_clock::time_point lastAdvTime;
int lastRandomScene = -1;
inline SceneGroup(){};
inline SceneGroup(std::string name_) : name(name_){};
inline SceneGroup(std::string name_, AdvanceCondition type_,
std::vector<OBSWeakSource> scenes_, int count_,
double time_, bool repeat_)
: name(name_),
type(type_),
scenes(scenes_),
count(count_),
time(time_),
repeat(repeat_)
{
}
};
class SceneGroupEditWidget : public QWidget {
Q_OBJECT
public:
SceneGroupEditWidget();
void SetEditSceneGroup(SceneGroup *sg);
void ShowCurrentTypeEdit();
private slots:
void TypeChanged(int type);
void CountChanged(int count);
void TimeChanged(double time);
void RepeatChanged(int state);
private:
QComboBox *type;
QWidget *timeEdit;
QWidget *countEdit;
QSpinBox *count;
QDoubleSpinBox *time;
QLabel *random;
QCheckBox *repeat;
SceneGroup *sceneGroup = nullptr;
};

View File

@@ -0,0 +1,73 @@
#pragma once
#include "switch-generic.hpp"
enum class sceneTriggerType {
NONE = 0,
SCENE_ACTIVE = 1,
SCENE_INACTIVE = 2,
SCENE_LEAVE = 3,
};
enum class sceneTriggerAction {
NONE = 0,
START_RECORDING,
PAUSE_RECORDING,
UNPAUSE_RECORDING,
STOP_RECORDING,
START_STREAMING,
STOP_STREAMING,
START_REPLAY_BUFFER,
STOP_REPLAY_BUFFER,
MUTE_SOURCE,
UNMUTE_SOURCE,
START_SWITCHER,
STOP_SWITCHER,
};
struct SceneTrigger : SceneSwitcherEntry {
static bool pause;
sceneTriggerType triggerType = sceneTriggerType::NONE;
sceneTriggerAction triggerAction = sceneTriggerAction::NONE;
double duration = 0;
OBSWeakSource audioSource = nullptr;
const char *getType() { return "trigger"; }
void save(obs_data_t *obj);
void load(obs_data_t *obj);
bool checkMatch(OBSWeakSource currentScene,
OBSWeakSource previousScene);
void performAction();
void logMatch();
};
class SceneTriggerWidget : public SwitchWidget {
Q_OBJECT
public:
SceneTriggerWidget(QWidget *parent, SceneTrigger *s);
SceneTrigger *getSwitchData();
void setSwitchData(SceneTrigger *s);
static void swapSwitchData(SceneTriggerWidget *s1,
SceneTriggerWidget *s2);
private slots:
void TriggerTypeChanged(int index);
void TriggerActionChanged(int index);
void DurationChanged(double dur);
void AudioSourceChanged(const QString &text);
private:
QComboBox *triggers;
QComboBox *actions;
QDoubleSpinBox *duration;
QComboBox *audioSources;
SceneTrigger *switchData;
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <obs.hpp>
#include <string>
#include <QImage>
#include <chrono>
class AdvSSScreenshotObj {
public:
AdvSSScreenshotObj(obs_source_t *source);
~AdvSSScreenshotObj();
void Screenshot();
void Download();
void Copy();
void MarkDone();
gs_texrender_t *texrender = nullptr;
gs_stagesurf_t *stagesurf = nullptr;
OBSWeakSource weakSource;
std::string path;
QImage image;
uint32_t cx = 0;
uint32_t cy = 0;
int stage = 0;
bool done = false;
std::chrono::high_resolution_clock::time_point time;
};

31
src/headers/section.hpp Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include <QFrame>
#include <QGridLayout>
#include <QParallelAnimationGroup>
#include <QScrollArea>
#include <QToolButton>
#include <QWidget>
class Section : public QWidget {
Q_OBJECT
public:
explicit Section(const int animationDuration = 300,
QWidget *parent = 0);
void SetContent(QWidget *w);
void AddHeaderWidget(QWidget *);
public slots:
void Collapse(bool collapsed);
private:
QGridLayout *_mainLayout;
QHBoxLayout *_headerWidgetLayout;
QToolButton *_toggleButton;
QFrame *_headerLine;
QParallelAnimationGroup *_toggleAnimation = nullptr;
QScrollArea *_contentArea = nullptr;
int _animationDuration;
};

View File

@@ -1,7 +1,9 @@
#pragma once
#include <QSpinBox>
#include <limits>
#include "switch-generic.hpp"
#include "duration-control.hpp"
#include "volume-control.hpp"
constexpr auto audio_func = 8;
@@ -17,14 +19,16 @@ struct AudioSwitch : virtual SceneSwitcherEntry {
OBSWeakSource audioSource = nullptr;
int volumeThreshold = 0;
audioCondition condition = ABOVE;
double duration = 0;
unsigned int matchCount = 0;
float peak = -1;
Duration duration;
bool ignoreInactiveSource = true;
float peak = -std::numeric_limits<float>::infinity();
obs_volmeter_t *volmeter = nullptr;
const char *getType() { return "audio"; }
bool initialized();
bool valid();
void save(obs_data_t *obj);
void load(obs_data_t *obj);
static void setVolumeLevel(void *data,
const float magnitude[MAX_AUDIO_CHANNELS],
const float peak[MAX_AUDIO_CHANNELS],
@@ -32,10 +36,6 @@ struct AudioSwitch : virtual SceneSwitcherEntry {
void resetVolmeter();
AudioSwitch(){};
AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
OBSWeakSource audioSource_, int volumeThreshold_,
audioCondition condition_, double duration_,
bool usePreviousScene_);
AudioSwitch(const AudioSwitch &other);
AudioSwitch(AudioSwitch &&other);
~AudioSwitch();
@@ -46,16 +46,18 @@ struct AudioSwitch : virtual SceneSwitcherEntry {
struct AudioSwitchFallback : virtual SceneSwitcherEntry {
const char *getType() { return "audio_fallback"; }
void save(obs_data_t *obj);
void load(obs_data_t *obj);
bool enable = false;
double duration = 0;
unsigned int matchCount = 0;
Duration duration;
};
class AudioSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
AudioSwitchWidget(AudioSwitch *s);
AudioSwitchWidget(QWidget *parent, AudioSwitch *s);
void UpdateVolmeterSource();
AudioSwitch *getSwitchData();
void setSwitchData(AudioSwitch *s);
@@ -68,12 +70,14 @@ private slots:
void VolumeThresholdChanged(int vol);
void ConditionChanged(int cond);
void DurationChanged(double dur);
void IgnoreInactiveChanged(int state);
private:
QComboBox *audioSources;
QComboBox *condition;
QSpinBox *audioVolumeThreshold;
QDoubleSpinBox *duration;
DurationSelection *duration;
QCheckBox *ignoreInactiveSource;
VolControl *volMeter;
AudioSwitch *switchData;
@@ -83,13 +87,13 @@ class AudioSwitchFallbackWidget : public SwitchWidget {
Q_OBJECT
public:
AudioSwitchFallbackWidget(AudioSwitchFallback *s);
AudioSwitchFallbackWidget(QWidget *parent, AudioSwitchFallback *s);
private slots:
void DurationChanged(double dur);
private:
QDoubleSpinBox *duration;
DurationSelection *duration;
AudioSwitchFallback *switchData;
};

View File

@@ -11,22 +11,15 @@ struct ExecutableSwitch : SceneSwitcherEntry {
bool inFocus = false;
const char *getType() { return "exec"; }
inline ExecutableSwitch(){};
inline ExecutableSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
const QString &exe_, bool inFocus_)
: SceneSwitcherEntry(scene_, transition_),
exe(exe_),
inFocus(inFocus_)
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class ExecutableSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
ExecutableSwitchWidget(ExecutableSwitch *s);
ExecutableSwitchWidget(QWidget *parent, ExecutableSwitch *s);
ExecutableSwitch *getSwitchData();
void setSwitchData(ExecutableSwitch *s);

View File

@@ -23,29 +23,15 @@ struct FileSwitch : SceneSwitcherEntry {
size_t lastHash = 0;
const char *getType() { return "file"; }
inline FileSwitch(){};
inline FileSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
const char *file_, const char *text_, bool remote_,
bool useRegex_, bool useTime_,
bool onlyMatchIfChanged_)
: SceneSwitcherEntry(scene_, transition_),
file(file_),
text(text_),
remote(remote_),
useRegex(useRegex_),
useTime(useTime_),
onlyMatchIfChanged(onlyMatchIfChanged_),
lastMod()
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class FileSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
FileSwitchWidget(FileSwitch *s);
FileSwitchWidget(QWidget *parent, FileSwitch *s);
FileSwitch *getSwitchData();
void setSwitchData(FileSwitch *s);

View File

@@ -2,15 +2,36 @@
#include <obs.hpp>
#include <QComboBox>
#include "scene-group.hpp"
enum class SwitchTargetType {
Scene,
SceneGroup,
};
struct SceneSwitcherEntry {
SwitchTargetType targetType = SwitchTargetType::Scene;
SceneGroup *group = nullptr;
OBSWeakSource scene = nullptr;
OBSWeakSource transition = nullptr;
bool usePreviousScene = false;
bool useCurrentTransition = false;
virtual const char *getType() = 0;
virtual bool initialized();
virtual bool valid();
virtual void logMatchScene();
virtual void logMatchSceneGroup();
virtual void logMatch();
virtual OBSWeakSource getScene();
virtual void save(obs_data_t *obj,
const char *targetTypeSaveName = "targetType",
const char *targetSaveName = "target",
const char *transitionSaveName = "transition");
virtual void load(obs_data_t *obj,
const char *targetTypeLoadName = "targetType",
const char *targetLoadName = "target",
const char *transitionLoadName = "transition");
inline SceneSwitcherEntry() {}
@@ -23,6 +44,26 @@ struct SceneSwitcherEntry {
{
}
inline SceneSwitcherEntry(SceneGroup *group_, OBSWeakSource transition_,
bool usePreviousScene_ = false)
: group(group_),
transition(transition_),
usePreviousScene(usePreviousScene_)
{
}
inline SceneSwitcherEntry(SwitchTargetType targetType_,
SceneGroup *group_, OBSWeakSource scene_,
OBSWeakSource transition_,
bool usePreviousScene_ = false)
: targetType(targetType_),
group(group_),
scene(scene_),
transition(transition_),
usePreviousScene(usePreviousScene_)
{
}
virtual ~SceneSwitcherEntry() {}
};
@@ -30,15 +71,21 @@ class SwitchWidget : public QWidget {
Q_OBJECT
public:
SwitchWidget(SceneSwitcherEntry *s, bool usePreviousScene = true);
SwitchWidget(QWidget *parent, SceneSwitcherEntry *s,
bool usePreviousScene = true, bool addSceneGroup = false,
bool addCurrentTransition = true);
virtual SceneSwitcherEntry *getSwitchData();
virtual void setSwitchData(SceneSwitcherEntry *s);
void showSwitchData();
static void swapSwitchData(SwitchWidget *s1, SwitchWidget *s2);
private slots:
protected slots:
void SceneChanged(const QString &text);
void TransitionChanged(const QString &text);
void SceneGroupAdd(const QString &name);
void SceneGroupRemove(const QString &name);
void SceneGroupRename(const QString &oldName, const QString &newName);
protected:
bool loading = true;

View File

@@ -12,4 +12,21 @@ struct IdleData : SceneSwitcherEntry {
bool alreadySwitched = false;
const char *getType() { return "idle"; }
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class IdleWidget : public SwitchWidget {
Q_OBJECT
public:
IdleWidget(QWidget *parent, IdleData *s);
private slots:
void DurationChanged(int dur);
private:
QSpinBox *duration;
IdleData *switchData;
};

View File

@@ -20,13 +20,13 @@ struct MediaSwitch : SceneSwitcherEntry {
time_restriction restriction = TIME_RESTRICTION_NONE;
int64_t time = 0;
// trigger scene change only once even if media state might trigger repeatedly
// Trigger scene change only once even if media state might trigger repeatedly
bool matched = false;
std::atomic_bool stopped = {false};
std::atomic_bool ended = {false};
// workaround to enable use of "ended" to specify end of VLC playlist
// Workaround to enable use of "ended" to specify end of VLC playlist
bool previousStateEnded = false;
bool playedToEnd = false;
@@ -34,6 +34,8 @@ struct MediaSwitch : SceneSwitcherEntry {
const char *getType() { return "media"; }
bool initialized();
bool valid();
void save(obs_data_t *obj);
void load(obs_data_t *obj);
void clearSignalHandler();
void resetSignalHandler();
@@ -41,10 +43,7 @@ struct MediaSwitch : SceneSwitcherEntry {
static void MediaEnded(void *data, calldata_t *);
inline MediaSwitch(){};
inline MediaSwitch(OBSWeakSource scene_, OBSWeakSource source_,
OBSWeakSource transition_, obs_media_state state_,
time_restriction restriction_, uint64_t time_,
bool usePreviousScene_);
MediaSwitch(const MediaSwitch &other);
MediaSwitch(MediaSwitch &&other);
~MediaSwitch();
@@ -57,7 +56,7 @@ class MediaSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
MediaSwitchWidget(MediaSwitch *s);
MediaSwitchWidget(QWidget *parent, MediaSwitch *s);
MediaSwitch *getSwitchData();
void setSwitchData(MediaSwitch *s);

View File

@@ -0,0 +1,113 @@
/*
Most of this code is based on https://github.com/Palakis/obs-websocket
*/
#pragma once
#include <set>
#include <QtCore/QObject>
#include <QtCore/QMutex>
#include <QtCore/QSharedPointer>
#include <QtCore/QVariantHash>
#include <QtCore/QThreadPool>
#include <mutex>
#include <condition_variable>
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <websocketpp/client.hpp>
using websocketpp::connection_hdl;
typedef websocketpp::server<websocketpp::config::asio> server;
typedef websocketpp::client<websocketpp::config::asio_client> client;
struct sceneSwitchInfo;
class NetworkConfig {
public:
NetworkConfig();
void Load(obs_data_t *obj);
void Save(obs_data_t *obj);
void SetDefaults(obs_data_t *obj);
std::string GetClientUri();
// Server
bool ServerEnabled;
uint64_t ServerPort;
bool LockToIPv4;
// Client
bool ClientEnabled;
std::string Address;
uint64_t ClientPort;
bool SendAll;
};
class WSServer : public QObject {
Q_OBJECT
public:
explicit WSServer();
virtual ~WSServer();
void start(quint16 port, bool lockToIPv4);
void stop();
void sendMessage(sceneSwitchInfo sceneSwitch);
QThreadPool *threadPool() { return &_threadPool; }
private:
void onOpen(connection_hdl hdl);
void onMessage(connection_hdl hdl, server::message_ptr message);
void onClose(connection_hdl hdl);
QString getRemoteEndpoint(connection_hdl hdl);
server _server;
quint16 _serverPort;
bool _lockToIPv4;
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
QMutex _clMutex;
QThreadPool _threadPool;
};
enum class ServerStatus {
NOT_RUNNING,
STARTING,
RUNNING,
};
class WSClient : public QObject {
Q_OBJECT
public:
explicit WSClient();
virtual ~WSClient();
void connect(std::string uri);
void disconnect();
std::string getFail() { return _failMsg; }
private:
void onOpen(connection_hdl hdl);
void onFail(connection_hdl hdl);
void onMessage(connection_hdl hdl, client::message_ptr message);
void onClose(connection_hdl hdl);
void connectThread();
client _client;
std::string _uri;
connection_hdl _connection;
std::thread _thread;
bool _retry = false;
std::atomic_bool _connected = {false};
std::mutex _waitMtx;
std::condition_variable _cv;
std::string _failMsg;
};
enum class ClientStatus {
DISCONNECTED,
CONNECTING,
CONNECTED,
FAIL,
};

View File

@@ -19,6 +19,7 @@ enum class PauseTarget {
Idle,
Sequence,
Audio,
Video,
};
struct PauseEntry : SceneSwitcherEntry {
@@ -44,7 +45,7 @@ class PauseEntryWidget : public SwitchWidget {
Q_OBJECT
public:
PauseEntryWidget(PauseEntry *s);
PauseEntryWidget(QWidget *parent, PauseEntry *s);
PauseEntry *getSwitchData();
void setSwitchData(PauseEntry *s);

View File

@@ -6,20 +6,15 @@ struct RandomSwitch : SceneSwitcherEntry {
double delay = 0.0;
const char *getType() { return "random"; }
inline RandomSwitch() {}
inline RandomSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
double delay_)
: SceneSwitcherEntry(scene_, transition_), delay(delay_)
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class RandomSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
RandomSwitchWidget(RandomSwitch *s);
RandomSwitchWidget(QWidget *parent, RandomSwitch *s);
RandomSwitch *getSwitchData();
void setSwitchData(RandomSwitch *s);

View File

@@ -7,28 +7,19 @@ constexpr auto default_priority_4 = screen_region_func;
struct ScreenRegionSwitch : SceneSwitcherEntry {
static bool pause;
OBSWeakSource excludeScene = nullptr;
int minX = 0, minY = 0, maxX = 0, maxY = 0;
const char *getType() { return "region"; }
inline ScreenRegionSwitch(){};
inline ScreenRegionSwitch(OBSWeakSource scene_,
OBSWeakSource transition_, int minX_,
int minY_, int maxX_, int maxY_)
: SceneSwitcherEntry(scene_, transition_),
minX(minX_),
minY(minY_),
maxX(maxX_),
maxY(maxY_)
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class ScreenRegionWidget : public SwitchWidget {
Q_OBJECT
public:
ScreenRegionWidget(ScreenRegionSwitch *s);
ScreenRegionWidget(QWidget *parent, ScreenRegionSwitch *s);
ScreenRegionSwitch *getSwitchData();
void setSwitchData(ScreenRegionSwitch *s);
@@ -39,12 +30,14 @@ public:
void hideFrame();
private slots:
void ExcludeSceneChanged(const QString &text);
void MinXChanged(int pos);
void MinYChanged(int pos);
void MaxXChanged(int pos);
void MaxYChanged(int pos);
private:
QComboBox *excludeScenes;
QSpinBox *minX;
QSpinBox *minY;
QSpinBox *maxX;

View File

@@ -1,66 +1,81 @@
#pragma once
#include <QVBoxLayout>
#include "switch-generic.hpp"
#include "duration-control.hpp"
constexpr auto round_trip_func = 1;
constexpr auto default_priority_1 = round_trip_func;
typedef enum {
SECONDS,
MINUTES,
HOURS,
} delay_units;
struct SceneSequenceSwitch : SceneSwitcherEntry {
static bool pause;
SwitchTargetType startTargetType = SwitchTargetType::Scene;
OBSWeakSource startScene = nullptr;
double delay = 0;
int delayMultiplier = 1;
Duration delay;
bool interruptible = false;
unsigned int matchCount = 0;
// nullptr marks start point and reaching end of extended sequence
SceneSequenceSwitch *activeSequence = nullptr;
std::unique_ptr<SceneSequenceSwitch> extendedSequence = nullptr;
const char *getType() { return "sequence"; }
bool initialized();
bool valid();
void logSleep(int dur);
void save(obs_data_t *obj, bool saveExt = true);
void load(obs_data_t *obj, bool saveExt = true);
inline SceneSequenceSwitch(){};
inline SceneSequenceSwitch(OBSWeakSource startScene_,
OBSWeakSource scene_,
OBSWeakSource transition_, double delay_,
int delayMultiplier_, bool interruptible_,
bool usePreviousScene_)
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
startScene(startScene_),
delay(delay_),
delayMultiplier(delayMultiplier_),
interruptible(interruptible_)
{
}
bool reduce();
SceneSequenceSwitch *extend();
bool checkMatch(OBSWeakSource currentScene, int &linger,
SceneSequenceSwitch *root = nullptr);
bool checkDurationMatchInterruptible();
void prepareUninterruptibleMatch(OBSWeakSource currentScene,
int &linger);
void advanceActiveSequence();
void logAdvanceSequence();
void logSequenceCanceled();
};
class SequenceWidget : public SwitchWidget {
Q_OBJECT
public:
SequenceWidget(SceneSequenceSwitch *s);
SequenceWidget(QWidget *parent, SceneSequenceSwitch *s,
bool extendSequence = false, bool editExtendMode = false,
bool showExtendText = true);
SceneSequenceSwitch *getSwitchData();
void setSwitchData(SceneSequenceSwitch *s);
static void swapSwitchData(SequenceWidget *s1, SequenceWidget *s2);
void UpdateDelay();
void UpdateWidgetStatus(bool showExtendText);
void setExtendedSequenceStartScene();
private slots:
void SceneChanged(const QString &text);
void DelayChanged(double delay);
void DelayUnitsChanged(int idx);
void DelayUnitsChanged(DurationUnit);
void StartSceneChanged(const QString &text);
void InterruptibleChanged(int state);
void ExtendClicked();
void ReduceClicked();
private:
QDoubleSpinBox *delay;
QComboBox *delayUnits;
protected:
DurationSelection *delay;
QComboBox *startScenes;
QCheckBox *interruptible;
QVBoxLayout *extendSequenceLayout;
QPushButton *extend;
QPushButton *reduce;
// I would prefer having a list of only widgets of type editExtendMode
// but I am not sure how to best implement that using a QListWidget.
//
// So use edit button to bring up edit widget and
// add a label to disaplay current extended sequence state.
QLabel *extendText;
SceneSequenceSwitch *switchData;
};

View File

@@ -24,23 +24,15 @@ struct TimeSwitch : SceneSwitcherEntry {
QTime time = QTime(0, 0);
const char *getType() { return "time"; }
inline TimeSwitch(){};
inline TimeSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
timeTrigger trigger_, QTime time_,
bool usePreviousScene_)
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
trigger(trigger_),
time(time_)
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class TimeSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
TimeSwitchWidget(TimeSwitch *s);
TimeSwitchWidget(QWidget *parent, TimeSwitch *s);
TimeSwitch *getSwitchData();
void setSwitchData(TimeSwitch *s);

View File

@@ -1,25 +1,37 @@
#pragma once
#include <QDoubleSpinBox>
#include "switch-generic.hpp"
struct SceneTransition : SceneSwitcherEntry {
OBSWeakSource scene2 = nullptr;
double duration = 0.3;
const char *getType() { return "transition"; }
bool initialized();
bool valid();
void save(obs_data_t *obj);
void load(obs_data_t *obj);
inline SceneTransition(){};
inline SceneTransition(OBSWeakSource scene_, OBSWeakSource scene2_,
OBSWeakSource transition_)
: SceneSwitcherEntry(scene_, transition_), scene2(scene2_)
OBSWeakSource transition_, double duration_)
: SceneSwitcherEntry(scene_, transition_),
scene2(scene2_),
duration(duration_)
{
}
};
struct DefaultSceneTransition : SceneSwitcherEntry {
static bool pause;
static unsigned int delay;
const char *getType() { return "def_transition"; }
void save(obs_data_t *obj);
void load(obs_data_t *obj);
bool checkMatch(OBSWeakSource currentScene);
void setTransition();
inline DefaultSceneTransition(){};
inline DefaultSceneTransition(OBSWeakSource scene_,
@@ -33,7 +45,7 @@ class TransitionSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
TransitionSwitchWidget(SceneTransition *s);
TransitionSwitchWidget(QWidget *parent, SceneTransition *s);
SceneTransition *getSwitchData();
void setSwitchData(SceneTransition *s);
@@ -42,9 +54,11 @@ public:
private slots:
void Scene2Changed(const QString &text);
void DurationChanged(double dur);
private:
QComboBox *scenes2;
QDoubleSpinBox *duration;
SceneTransition *switchData;
};
@@ -53,7 +67,7 @@ class DefTransitionSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
DefTransitionSwitchWidget(DefaultSceneTransition *s);
DefTransitionSwitchWidget(QWidget *parent, DefaultSceneTransition *s);
DefaultSceneTransition *getSwitchData();
void setSwitchData(DefaultSceneTransition *s);

View File

@@ -0,0 +1,76 @@
#pragma once
#include <QSpinBox>
#include "switch-generic.hpp"
#include "screenshot-helper.hpp"
constexpr auto video_func = 9;
constexpr auto default_priority_9 = video_func;
enum class videoSwitchType {
MATCH,
DIFFER,
HAS_NOT_CHANGED,
HAS_CHANGED,
};
struct VideoSwitch : virtual SceneSwitcherEntry {
static bool pause;
videoSwitchType condition = videoSwitchType::MATCH;
OBSWeakSource videoSource = nullptr;
std::string file = obs_module_text("AdvSceneSwitcher.enterPath");
double duration = 0;
bool ignoreInactiveSource = false;
std::unique_ptr<AdvSSScreenshotObj> screenshotData = nullptr;
std::chrono::high_resolution_clock::time_point previousTime{};
QImage matchImage;
std::chrono::milliseconds currentMatchDuration{};
const char *getType() { return "video"; }
bool initialized();
bool valid();
void save(obs_data_t *obj);
void load(obs_data_t *obj);
void getScreenshot();
bool loadImageFromFile();
bool checkMatch();
VideoSwitch(){};
friend void swap(VideoSwitch &first, VideoSwitch &second);
};
class VideoSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
VideoSwitchWidget(QWidget *parent, VideoSwitch *s);
VideoSwitch *getSwitchData();
void setSwitchData(VideoSwitch *s);
static void swapSwitchData(VideoSwitchWidget *as1,
VideoSwitchWidget *as2);
void UpdatePreviewTooltip();
void SetFilePath(const QString &text);
private slots:
void SourceChanged(const QString &text);
void ConditionChanged(int cond);
void DurationChanged(double dur);
void FilePathChanged();
void BrowseButtonClicked();
void IgnoreInactiveChanged(int state);
private:
QComboBox *videoSources;
QComboBox *condition;
QDoubleSpinBox *duration;
QLineEdit *filePath;
QPushButton *browseButton;
QCheckBox *ignoreInactiveSource;
VideoSwitch *switchData;
};

View File

@@ -12,25 +12,15 @@ struct WindowSwitch : SceneSwitcherEntry {
bool focus = true;
const char *getType() { return "window"; }
inline WindowSwitch() {}
inline WindowSwitch(OBSWeakSource scene_, const char *window_,
OBSWeakSource transition_, bool fullscreen_,
bool maximized_, bool focus_)
: SceneSwitcherEntry(scene_, transition_),
window(window_),
fullscreen(fullscreen_),
maximized(maximized_),
focus(focus_)
{
}
void save(obs_data_t *obj);
void load(obs_data_t *obj);
};
class WindowSwitchWidget : public SwitchWidget {
Q_OBJECT
public:
WindowSwitchWidget(WindowSwitch *s);
WindowSwitchWidget(QWidget *parent, WindowSwitch *s);
WindowSwitch *getSwitchData();
void setSwitchData(WindowSwitch *s);

View File

@@ -7,6 +7,8 @@
#include <QThread>
#include <curl/curl.h>
#include "scene-group.hpp"
#include "scene-trigger.hpp"
#include "switch-audio.hpp"
#include "switch-executable.hpp"
#include "switch-file.hpp"
@@ -19,17 +21,33 @@
#include "switch-transitions.hpp"
#include "switch-window.hpp"
#include "switch-sequence.hpp"
#include "switch-video.hpp"
#include "switch-network.hpp"
#include "macro.hpp"
#include "duration-control.hpp"
constexpr auto default_interval = 300;
constexpr auto previous_scene_name = "Previous Scene";
constexpr auto current_transition_name = "Current Transition";
constexpr auto tab_count = 18;
typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
typedef enum { PERSIST = 0, START = 1, STOP = 2 } StartupBehavior;
typedef enum {
RECORDING = 0,
STREAMING = 1,
RECORINDGSTREAMING = 2
} AutoStartType;
enum class AutoStartEvent {
NEVER,
RECORDING,
STREAMING,
RECORINDG_OR_STREAMING,
};
typedef struct sceneSwitchInfo {
OBSWeakSource scene;
OBSWeakSource transition;
int duration = 0;
} sceneSwitchInfo;
typedef struct transitionData {
std::string name = "";
@@ -54,23 +72,30 @@ struct SwitcherData {
bool verbose = false;
bool disableHints = false;
bool showFrame = false;
bool tansitionOverrideOverride = false;
bool transitionOverrideOverride = false;
bool adjustActiveTransitionType = true;
int interval = default_interval;
obs_source_t *waitScene = nullptr;
OBSWeakSource previousScene = nullptr;
OBSWeakSource previousScene2 = nullptr;
OBSWeakSource previousSceneHelper = nullptr;
OBSWeakSource lastRandomScene;
SceneGroup *lastRandomSceneGroup;
OBSWeakSource nonMatchingScene;
NoMatch switchIfNotMatching = NO_SWITCH;
double noMatchDelay;
double noMatchCount = 0;
Duration noMatchDelay;
StartupBehavior startupBehavior = PERSIST;
AutoStartEvent autoStartEvent = AutoStartEvent::NEVER;
double cooldown = 0.;
Duration cooldown;
std::chrono::high_resolution_clock::time_point lastMatchTime;
std::deque<Macro> macros;
// Allow only one macro scene change per scene switcher interval
// with the top macro having the highest priority
bool macroSceneSwitched = false;
std::deque<WindowSwitch> windowSwitches;
std::vector<std::string> ignoreIdleWindows;
std::string lastTitle;
@@ -79,6 +104,7 @@ struct SwitcherData {
std::vector<std::string> ignoreWindowsSwitches;
bool uninterruptibleSceneSequenceActive = false;
std::deque<SceneSequenceSwitch> sceneSequenceSwitches;
std::deque<RandomSwitch> randomSwitches;
@@ -91,17 +117,10 @@ struct SwitcherData {
std::deque<ExecutableSwitch> executableSwitches;
bool autoStopEnable = false;
OBSWeakSource autoStopScene;
bool autoStartEnable = false;
AutoStartType autoStartType = RECORDING;
OBSWeakSource autoStartScene;
bool autoStartedRecently = false;
std::deque<SceneTrigger> sceneTriggers;
std::deque<SceneTransition> sceneTransitions;
std::deque<DefaultSceneTransition> defaultSceneTransitions;
bool checkedDefTransition = false;
std::deque<MediaSwitch> mediaSwitches;
@@ -113,10 +132,21 @@ struct SwitcherData {
std::deque<AudioSwitch> audioSwitches;
AudioSwitchFallback audioFallback;
WSServer server;
ServerStatus serverStatus = ServerStatus::NOT_RUNNING;
WSClient client;
ClientStatus clientStatus = ClientStatus::DISCONNECTED;
NetworkConfig networkConfig;
std::deque<VideoSwitch> videoSwitches;
std::deque<SceneGroup> sceneGroups;
std::vector<int> functionNamesByPriority = std::vector<int>{
default_priority_0, default_priority_1, default_priority_2,
default_priority_3, default_priority_4, default_priority_5,
default_priority_6, default_priority_7, default_priority_8};
default_priority_6, default_priority_7, default_priority_8,
default_priority_9, default_priority_10};
struct ThreadPrio {
std::string name;
@@ -145,56 +175,66 @@ struct SwitcherData {
uint32_t threadPriority = QThread::NormalPriority;
std::vector<int> tabOrder;
std::vector<int> tabOrder = std::vector<int>(tab_count);
bool hotkeysRegistered = false;
obs_hotkey_id startHotkey = 0;
obs_hotkey_id stopHotkey = 0;
obs_hotkey_id toggleHotkey = 0;
bool saveWindowGeo = false;
QPoint windowPos = {};
QSize windowSize = {};
bool versionChanged(obs_data_t *obj, std::string currentVersion);
void Thread();
void Start();
void Stop();
bool sceneChangedDuringWait();
bool prioFuncsValid();
bool tabOrderValid();
void resetTabOrder();
void writeSceneInfoToFile();
void writeToStatusFile(QString status);
void autoStopStreamAndRecording();
void autoStartStreamRecording();
bool checkPause();
void checkDefaultSceneTransitions(bool &match,
OBSWeakSource &transition);
void setCurrentDefTransition(OBSWeakSource &transition);
void checkSceneSequence(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition,
std::unique_lock<std::mutex> &lock);
void checkIdleSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
void checkWindowTitleSwitch(bool &match, OBSWeakSource &scene,
bool checkForMatch(OBSWeakSource &scene, OBSWeakSource &transition,
int &linger, bool &setPreviousSceneAsMatch,
bool &macroMatch);
bool checkMacros();
bool runMacros();
bool checkSceneSequence(OBSWeakSource &scene, OBSWeakSource &transition,
int &linger, bool &setPrevSceneAfterLinger);
bool checkIdleSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
bool checkWindowTitleSwitch(OBSWeakSource &scene,
OBSWeakSource &transition);
void checkExeSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
void checkScreenRegionSwitch(bool &match, OBSWeakSource &scene,
bool checkExeSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
bool checkScreenRegionSwitch(OBSWeakSource &scene,
OBSWeakSource &transition);
void checkSwitchInfoFromFile(bool &match, OBSWeakSource &scene,
bool checkSwitchInfoFromFile(OBSWeakSource &scene,
OBSWeakSource &transition);
void checkFileContent(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
void checkRandom(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition, int &delay);
void checkMediaSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
void checkTimeSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
void checkAudioSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition);
bool checkFileContent(OBSWeakSource &scene, OBSWeakSource &transition);
bool checkRandom(OBSWeakSource &scene, OBSWeakSource &transition,
int &delay);
bool checkMediaSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
bool checkTimeSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
bool checkAudioSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
void checkAudioSwitchFallback(OBSWeakSource &scene,
OBSWeakSource &transition);
bool checkVideoSwitch(OBSWeakSource &scene, OBSWeakSource &transition);
void checkNoMatchSwitch(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition, int &sleep);
void checkSwitchCooldown(bool &match);
void checkTriggers();
bool checkPause();
void checkDefaultSceneTransitions();
void saveSettings(obs_data_t *obj);
void saveMacros(obs_data_t *obj);
void saveWindowTitleSwitches(obs_data_t *obj);
void saveScreenRegionSwitches(obs_data_t *obj);
void savePauseSwitches(obs_data_t *obj);
@@ -207,13 +247,19 @@ struct SwitcherData {
void saveMediaSwitches(obs_data_t *obj);
void saveTimeSwitches(obs_data_t *obj);
void saveAudioSwitches(obs_data_t *obj);
void saveSceneGroups(obs_data_t *obj);
void saveSceneTriggers(obs_data_t *obj);
void saveVideoSwitches(obs_data_t *obj);
void saveNetworkSwitches(obs_data_t *obj);
void saveGeneralSettings(obs_data_t *obj);
void saveHotkeys(obs_data_t *obj);
void saveVersion(obs_data_t *obj, std::string currentVersion);
void loadSettings(obs_data_t *obj);
void loadMacros(obs_data_t *obj);
void loadWindowTitleSwitches(obs_data_t *obj);
void loadScreenRegionSwitches(obs_data_t *obj);
void loadPauseSwitches(obs_data_t *obj);
void loadOldPauseSwitches(obs_data_t *obj);
void loadSceneSequenceSwitches(obs_data_t *obj);
void loadSceneTransitions(obs_data_t *obj);
void loadIdleSwitches(obs_data_t *obj);
@@ -223,6 +269,10 @@ struct SwitcherData {
void loadMediaSwitches(obs_data_t *obj);
void loadTimeSwitches(obs_data_t *obj);
void loadAudioSwitches(obs_data_t *obj);
void loadSceneGroups(obs_data_t *obj);
void loadSceneTriggers(obs_data_t *obj);
void loadVideoSwitches(obs_data_t *obj);
void loadNetworkSettings(obs_data_t *obj);
void loadGeneralSettings(obs_data_t *obj);
void loadHotkeys(obs_data_t *obj);

View File

@@ -1,8 +1,10 @@
#pragma once
#include <QString>
#include <QTextStream>
#include <QLayout>
#include <QLabel>
#include <QMessageBox>
#include <unordered_map>
#include <obs.hpp>
@@ -12,8 +14,9 @@
static inline bool WeakSourceValid(obs_weak_source_t *ws)
{
obs_source_t *source = obs_weak_source_get_source(ws);
if (source)
if (source) {
obs_source_release(source);
}
return !!source;
}
@@ -104,8 +107,9 @@ getNextDelim(std::string text,
}
}
if (pos == std::string::npos)
if (pos == std::string::npos) {
return "";
}
return res;
}
@@ -141,11 +145,72 @@ placeWidgets(std::string text, QBoxLayout *layout,
}
for (auto &lw : labelsWidgetsPairs) {
if (lw.first != "")
if (lw.first != "") {
layout->addWidget(new QLabel(lw.first.c_str()));
if (lw.second)
}
if (lw.second) {
layout->addWidget(lw.second);
}
}
if (addStretch)
if (addStretch) {
layout->addStretch();
}
}
static inline void clearLayout(QLayout *layout)
{
QLayoutItem *item;
while ((item = layout->takeAt(0))) {
if (item->layout()) {
clearLayout(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
}
}
static inline bool compareIgnoringLineEnding(QString &s1, QString &s2)
{
// Let QT deal with different types of lineendings
QTextStream s1stream(&s1);
QTextStream s2stream(&s2);
while (!s1stream.atEnd() || !s2stream.atEnd()) {
QString s1s = s1stream.readLine();
QString s2s = s2stream.readLine();
if (s1s != s2s) {
return false;
}
}
if (!s1stream.atEnd() && !s2stream.atEnd()) {
return false;
}
return true;
}
static inline bool DisplayMessage(QString msg, bool question = false)
{
if (question) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(
nullptr, "Advanced Scene Switcher", msg,
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
return true;
} else {
return false;
}
} else {
QMessageBox Msgbox;
Msgbox.setWindowTitle("Advanced Scene Switcher");
Msgbox.setText(msg);
Msgbox.exec();
}
return false;
}

View File

@@ -11,8 +11,9 @@ void startHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
UNUSED_PARAMETER(hotkey);
if (pressed) {
if (!(switcher->th && switcher->th->isRunning()))
if (!(switcher->th && switcher->th->isRunning())) {
switcher->Start();
}
}
}
@@ -24,8 +25,9 @@ void stopHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
UNUSED_PARAMETER(hotkey);
if (pressed) {
if (switcher->th && switcher->th->isRunning())
if (switcher->th && switcher->th->isRunning()) {
switcher->Stop();
}
}
}
@@ -37,10 +39,11 @@ void startStopToggleHotkeyFunc(void *data, obs_hotkey_id id,
UNUSED_PARAMETER(hotkey);
if (pressed) {
if (switcher->th && switcher->th->isRunning())
if (switcher->th && switcher->th->isRunning()) {
switcher->Stop();
else
} else {
switcher->Start();
}
}
}
@@ -65,40 +68,38 @@ void registerHotkeys()
void SwitcherData::saveHotkeys(obs_data_t *obj)
{
obs_data_array_t *startHotkeyArrray =
obs_hotkey_save(switcher->startHotkey);
obs_data_array_t *startHotkeyArrray = obs_hotkey_save(startHotkey);
obs_data_set_array(obj, "startHotkey", startHotkeyArrray);
obs_data_array_release(startHotkeyArrray);
obs_data_array_t *stopHotkeyArrray =
obs_hotkey_save(switcher->stopHotkey);
obs_data_array_t *stopHotkeyArrray = obs_hotkey_save(stopHotkey);
obs_data_set_array(obj, "stopHotkey", stopHotkeyArrray);
obs_data_array_release(stopHotkeyArrray);
obs_data_array_t *toggleHotkeyArrray =
obs_hotkey_save(switcher->toggleHotkey);
obs_data_array_t *toggleHotkeyArrray = obs_hotkey_save(toggleHotkey);
obs_data_set_array(obj, "toggleHotkey", toggleHotkeyArrray);
obs_data_array_release(toggleHotkeyArrray);
}
void SwitcherData::loadHotkeys(obs_data_t *obj)
{
if (!switcher->hotkeysRegistered)
if (!hotkeysRegistered) {
registerHotkeys();
}
obs_data_array_t *startHotkeyArrray =
obs_data_get_array(obj, "startHotkey");
obs_hotkey_load(switcher->startHotkey, startHotkeyArrray);
obs_hotkey_load(startHotkey, startHotkeyArrray);
obs_data_array_release(startHotkeyArrray);
obs_data_array_t *stopHotkeyArrray =
obs_data_get_array(obj, "stopHotkey");
obs_hotkey_load(switcher->stopHotkey, stopHotkeyArrray);
obs_hotkey_load(stopHotkey, stopHotkeyArrray);
obs_data_array_release(stopHotkeyArrray);
obs_data_array_t *toggleHotkeyArrray =
obs_data_get_array(obj, "toggleHotkey");
obs_hotkey_load(switcher->toggleHotkey, toggleHotkeyArrray);
obs_hotkey_load(toggleHotkey, toggleHotkeyArrray);
obs_data_array_release(toggleHotkeyArrray);
}

View File

@@ -14,7 +14,9 @@
#undef Status
#undef Unsorted
#include <util/platform.h>
#include "../headers/advanced-scene-switcher.hpp"
#include <vector>
#include <QStringList>
#include <QRegularExpression>
static Display *xdisplay = 0;
@@ -203,6 +205,10 @@ void GetCurrentWindowTitle(std::string &title)
&format, &num, &bytes,
(uint8_t **)&data);
if (data == nullptr) {
return;
}
int status = 0;
XTextProperty text;
if (xstatus == Success) {
@@ -386,4 +392,4 @@ int secondsSinceLastInput()
XCloseDisplay(display);
return idle_time;
}
}

186
src/macro-action-audio.cpp Normal file
View File

@@ -0,0 +1,186 @@
#include "headers/macro-action-audio.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
const int MacroActionAudio::id = 2;
bool MacroActionAudio::_registered = MacroActionFactory::Register(
MacroActionAudio::id,
{MacroActionAudio::Create, MacroActionAudioEdit::Create,
"AdvSceneSwitcher.action.audio"});
const static std::map<AudioAction, std::string> actionTypes = {
{AudioAction::MUTE, "AdvSceneSwitcher.action.audio.type.mute"},
{AudioAction::UNMUTE, "AdvSceneSwitcher.action.audio.type.unmute"},
{AudioAction::SOURCE_VOLUME,
"AdvSceneSwitcher.action.audio.type.sourceVolume"},
{AudioAction::MASTER_VOLUME,
"AdvSceneSwitcher.action.audio.type.masterVolume"},
};
bool MacroActionAudio::PerformAction()
{
auto s = obs_weak_source_get_source(_audioSource);
switch (_action) {
case AudioAction::MUTE:
obs_source_set_muted(s, true);
break;
case AudioAction::UNMUTE:
obs_source_set_muted(s, false);
break;
case AudioAction::SOURCE_VOLUME:
obs_source_set_volume(s, (float)_volume / 100.0f);
break;
case AudioAction::MASTER_VOLUME:
obs_set_master_volume((float)_volume / 100.0f);
break;
default:
break;
}
obs_source_release(s);
return true;
}
void MacroActionAudio::LogAction()
{
auto it = actionTypes.find(_action);
if (it != actionTypes.end()) {
vblog(LOG_INFO,
"performed action \"%s\" for source \"%s\" with volume %d",
it->second.c_str(),
GetWeakSourceName(_audioSource).c_str(), _volume);
} else {
blog(LOG_WARNING, "ignored unknown audio action %d",
static_cast<int>(_action));
}
}
bool MacroActionAudio::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
obs_data_set_string(obj, "audioSource",
GetWeakSourceName(_audioSource).c_str());
obs_data_set_int(obj, "action", static_cast<int>(_action));
obs_data_set_int(obj, "volume", _volume);
return true;
}
bool MacroActionAudio::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
const char *audioSourceName = obs_data_get_string(obj, "audioSource");
_audioSource = GetWeakSourceByName(audioSourceName);
_action = static_cast<AudioAction>(obs_data_get_int(obj, "action"));
_volume = obs_data_get_int(obj, "volume");
return true;
}
static inline void populateActionSelection(QComboBox *list)
{
for (auto entry : actionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroActionAudioEdit::MacroActionAudioEdit(
QWidget *parent, std::shared_ptr<MacroActionAudio> entryData)
: QWidget(parent)
{
_audioSources = new QComboBox();
_actions = new QComboBox();
_volumePercent = new QSpinBox();
_volumePercent->setMinimum(0);
_volumePercent->setMaximum(2000);
_volumePercent->setSuffix("%");
populateActionSelection(_actions);
AdvSceneSwitcher::populateAudioSelection(_audioSources);
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
SLOT(ActionChanged(int)));
QWidget::connect(_audioSources,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SourceChanged(const QString &)));
QWidget::connect(_volumePercent, SIGNAL(valueChanged(int)), this,
SLOT(VolumeChanged(int)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{audioSources}}", _audioSources},
{"{{actions}}", _actions},
{"{{volume}}", _volumePercent},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.audio.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
bool hasVolumeControl(AudioAction action)
{
return action == AudioAction::SOURCE_VOLUME ||
action == AudioAction::MASTER_VOLUME;
}
bool hasSourceControl(AudioAction action)
{
return action != AudioAction::MASTER_VOLUME;
}
void MacroActionAudioEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_audioSources->setCurrentText(
GetWeakSourceName(_entryData->_audioSource).c_str());
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
_volumePercent->setValue(_entryData->_volume);
if (hasVolumeControl(_entryData->_action)) {
_volumePercent->show();
} else {
_volumePercent->hide();
}
if (hasSourceControl(_entryData->_action)) {
_audioSources->show();
} else {
_audioSources->hide();
}
}
void MacroActionAudioEdit::SourceChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_audioSource = GetWeakSourceByQString(text);
}
void MacroActionAudioEdit::ActionChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_action = static_cast<AudioAction>(value);
UpdateEntryData();
}
void MacroActionAudioEdit::VolumeChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_volume = value;
}

135
src/macro-action-edit.cpp Normal file
View File

@@ -0,0 +1,135 @@
#include "headers/macro-action-edit.hpp"
#include "headers/macro-action-switch-scene.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
std::map<int, MacroActionInfo> MacroActionFactory::_methods;
bool MacroActionFactory::Register(int id, MacroActionInfo info)
{
if (auto it = _methods.find(id); it == _methods.end()) {
_methods[id] = info;
return true;
}
return false;
}
std::shared_ptr<MacroAction> MacroActionFactory::Create(const int id)
{
if (auto it = _methods.find(id); it != _methods.end())
return it->second._createFunc();
return nullptr;
}
QWidget *MacroActionFactory::CreateWidget(const int id, QWidget *parent,
std::shared_ptr<MacroAction> action)
{
if (auto it = _methods.find(id); it != _methods.end())
return it->second._createWidgetFunc(parent, action);
return nullptr;
}
static inline void populateActionSelection(QComboBox *list)
{
for (auto entry : MacroActionFactory::GetActionTypes()) {
list->addItem(obs_module_text(entry.second._name.c_str()));
}
}
MacroActionEdit::MacroActionEdit(QWidget *parent,
std::shared_ptr<MacroAction> *entryData,
int type, bool startCollapsed)
: QWidget(parent)
{
_actionSelection = new QComboBox();
_section = new Section(300);
QWidget::connect(_actionSelection, SIGNAL(currentIndexChanged(int)),
this, SLOT(ActionSelectionChanged(int)));
populateActionSelection(_actionSelection);
_section->AddHeaderWidget(_actionSelection);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(_section);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData(type);
_loading = false;
_section->Collapse(startCollapsed);
}
void MacroActionEdit::ActionSelectionChanged(int idx)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->reset();
*_entryData = MacroActionFactory::Create(idx);
auto widget =
MacroActionFactory::CreateWidget(idx, window(), *_entryData);
_section->SetContent(widget);
_section->Collapse(false);
}
void MacroActionEdit::UpdateEntryData(int type)
{
_actionSelection->setCurrentIndex(type);
auto widget =
MacroActionFactory::CreateWidget(type, window(), *_entryData);
_section->SetContent(widget);
}
void MacroActionEdit::Collapse(bool collapsed)
{
_section->Collapse(collapsed);
}
void AdvSceneSwitcher::on_actionAdd_clicked()
{
auto macro = getSelectedMacro();
if (!macro) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
macro->Actions().emplace_back(MacroActionFactory::Create(0));
auto newEntry = new MacroActionEdit(this, &macro->Actions().back(), 0);
ui->macroEditActionLayout->addWidget(newEntry);
ui->macroEditActionHelp->setVisible(false);
newEntry->Collapse(false);
}
void AdvSceneSwitcher::on_actionRemove_clicked()
{
auto macro = getSelectedMacro();
if (!macro) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (macro->Actions().empty()) {
return;
}
macro->Actions().pop_back();
int count = ui->macroEditActionLayout->count();
auto item = ui->macroEditActionLayout->takeAt(count - 1);
if (item) {
auto widget = item->widget();
if (widget) {
widget->setVisible(false);
}
delete item;
}
if (count == 1) {
ui->macroEditActionHelp->setVisible(true);
}
}

View File

@@ -0,0 +1,133 @@
#include "headers/macro-action-recording.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
const int MacroActionRecord::id = 4;
bool MacroActionRecord::_registered = MacroActionFactory::Register(
MacroActionRecord::id,
{MacroActionRecord::Create, MacroActionRecordEdit::Create,
"AdvSceneSwitcher.action.recording"});
const static std::map<RecordAction, std::string> actionTypes = {
{RecordAction::STOP, "AdvSceneSwitcher.action.recording.type.stop"},
{RecordAction::START, "AdvSceneSwitcher.action.recording.type.start"},
{RecordAction::PAUSE, "AdvSceneSwitcher.action.recording.type.pause"},
{RecordAction::UNPAUSE,
"AdvSceneSwitcher.action.recording.type.unpause"},
};
bool MacroActionRecord::PerformAction()
{
switch (_action) {
case RecordAction::STOP:
if (obs_frontend_recording_active()) {
obs_frontend_recording_stop();
}
break;
case RecordAction::START:
if (!obs_frontend_recording_active()) {
obs_frontend_recording_start();
}
break;
case RecordAction::PAUSE:
if (obs_frontend_recording_active() &&
!obs_frontend_recording_paused()) {
obs_frontend_recording_pause(true);
}
break;
case RecordAction::UNPAUSE:
if (obs_frontend_recording_active() &&
obs_frontend_recording_paused()) {
obs_frontend_recording_pause(false);
}
break;
default:
break;
}
return true;
}
void MacroActionRecord::LogAction()
{
auto it = actionTypes.find(_action);
if (it != actionTypes.end()) {
vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str());
} else {
blog(LOG_WARNING, "ignored unknown recording action %d",
static_cast<int>(_action));
}
}
bool MacroActionRecord::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
obs_data_set_int(obj, "action", static_cast<int>(_action));
return true;
}
bool MacroActionRecord::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_action = static_cast<RecordAction>(obs_data_get_int(obj, "action"));
return true;
}
static inline void populateActionSelection(QComboBox *list)
{
for (auto entry : actionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroActionRecordEdit::MacroActionRecordEdit(
QWidget *parent, std::shared_ptr<MacroActionRecord> entryData)
: QWidget(parent)
{
_actions = new QComboBox();
_pauseHint = new QLabel(obs_module_text(
"AdvSceneSwitcher.action.recording.pause.hint"));
populateActionSelection(_actions);
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
SLOT(ActionChanged(int)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{actions}}", _actions},
{"{{pauseHint}}", _pauseHint},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.recording.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
bool isPauseAction(RecordAction a)
{
return a == RecordAction::PAUSE || a == RecordAction::UNPAUSE;
}
void MacroActionRecordEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
_pauseHint->setVisible(isPauseAction(_entryData->_action));
}
void MacroActionRecordEdit::ActionChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_action = static_cast<RecordAction>(value);
_pauseHint->setVisible(isPauseAction(_entryData->_action));
}

View File

@@ -0,0 +1,121 @@
#include "headers/macro-action-replay-buffer.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
const int MacroActionReplayBuffer::id = 5;
bool MacroActionReplayBuffer::_registered = MacroActionFactory::Register(
MacroActionReplayBuffer::id,
{MacroActionReplayBuffer::Create, MacroActionReplayBufferEdit::Create,
"AdvSceneSwitcher.action.replay"});
const static std::map<ReplayBufferAction, std::string> actionTypes = {
{ReplayBufferAction::STOP, "AdvSceneSwitcher.action.replay.type.stop"},
{ReplayBufferAction::START,
"AdvSceneSwitcher.action.replay.type.start"},
{ReplayBufferAction::SAVE, "AdvSceneSwitcher.action.replay.type.save"},
};
bool MacroActionReplayBuffer::PerformAction()
{
switch (_action) {
case ReplayBufferAction::STOP:
if (obs_frontend_replay_buffer_active()) {
obs_frontend_replay_buffer_stop();
}
break;
case ReplayBufferAction::START:
if (!obs_frontend_replay_buffer_active()) {
obs_frontend_replay_buffer_start();
}
break;
case ReplayBufferAction::SAVE:
if (obs_frontend_replay_buffer_active() &&
_duration.DurationReached()) {
obs_frontend_replay_buffer_save();
// Default buffer size is 20s so waiting for 10s before
// trying to save again seems reasonable
_duration.seconds = 10;
_duration.Reset();
}
break;
default:
break;
}
return true;
}
void MacroActionReplayBuffer::LogAction()
{
auto it = actionTypes.find(_action);
if (it != actionTypes.end()) {
vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str());
} else {
blog(LOG_WARNING, "ignored unknown replay buffer action %d",
static_cast<int>(_action));
}
}
bool MacroActionReplayBuffer::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
obs_data_set_int(obj, "action", static_cast<int>(_action));
return true;
}
bool MacroActionReplayBuffer::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_action = static_cast<ReplayBufferAction>(
obs_data_get_int(obj, "action"));
return true;
}
static inline void populateActionSelection(QComboBox *list)
{
for (auto entry : actionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroActionReplayBufferEdit::MacroActionReplayBufferEdit(
QWidget *parent, std::shared_ptr<MacroActionReplayBuffer> entryData)
: QWidget(parent)
{
_actions = new QComboBox();
populateActionSelection(_actions);
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
SLOT(ActionChanged(int)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{actions}}", _actions},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.replay.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroActionReplayBufferEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
}
void MacroActionReplayBufferEdit::ActionChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_action = static_cast<ReplayBufferAction>(value);
}

98
src/macro-action-run.cpp Normal file
View File

@@ -0,0 +1,98 @@
#include "headers/macro-action-run.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
#include <QProcess>
#include <QFileDialog>
const int MacroActionRun::id = 6;
bool MacroActionRun::_registered = MacroActionFactory::Register(
MacroActionRun::id, {MacroActionRun::Create, MacroActionRunEdit::Create,
"AdvSceneSwitcher.action.run"});
bool MacroActionRun::PerformAction()
{
QProcess::startDetached(QString::fromStdString(_path), QStringList());
return true;
}
void MacroActionRun::LogAction()
{
vblog(LOG_INFO, "run \"%s\"", _path.c_str());
}
bool MacroActionRun::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
obs_data_set_string(obj, "path", _path.c_str());
return true;
}
bool MacroActionRun::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_path = obs_data_get_string(obj, "path");
return true;
}
MacroActionRunEdit::MacroActionRunEdit(
QWidget *parent, std::shared_ptr<MacroActionRun> entryData)
: QWidget(parent)
{
_filePath = new QLineEdit();
_browseButton =
new QPushButton(obs_module_text("AdvSceneSwitcher.browse"));
_browseButton->setStyleSheet("border:1px solid gray;");
QWidget::connect(_filePath, SIGNAL(editingFinished()), this,
SLOT(FilePathChanged()));
QWidget::connect(_browseButton, SIGNAL(clicked()), this,
SLOT(BrowseButtonClicked()));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{filePath}}", _filePath},
{"{{browseButton}}", _browseButton},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.run.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroActionRunEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_filePath->setText(QString::fromStdString(_entryData->_path));
}
void MacroActionRunEdit::FilePathChanged()
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_path = _filePath->text().toUtf8().constData();
}
void MacroActionRunEdit::BrowseButtonClicked()
{
if (_loading || !_entryData) {
return;
}
QString path = QFileDialog::getOpenFileName(this);
if (path.isEmpty()) {
return;
}
_filePath->setText(path);
FilePathChanged();
}

View File

@@ -0,0 +1,111 @@
#include "headers/macro-action-streaming.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
const int MacroActionStream::id = 3;
bool MacroActionStream::_registered = MacroActionFactory::Register(
MacroActionStream::id,
{MacroActionStream::Create, MacroActionStreamEdit::Create,
"AdvSceneSwitcher.action.streaming"});
const static std::map<StreamAction, std::string> actionTypes = {
{StreamAction::STOP, "AdvSceneSwitcher.action.streaming.type.stop"},
{StreamAction::START, "AdvSceneSwitcher.action.streaming.type.start"},
};
bool MacroActionStream::PerformAction()
{
switch (_action) {
case StreamAction::STOP:
if (obs_frontend_streaming_active()) {
obs_frontend_streaming_stop();
}
break;
case StreamAction::START:
if (!obs_frontend_streaming_active() &&
_retryCooldown.DurationReached()) {
obs_frontend_streaming_start();
_retryCooldown.seconds++;
_retryCooldown.Reset();
}
break;
default:
break;
}
return true;
}
void MacroActionStream::LogAction()
{
auto it = actionTypes.find(_action);
if (it != actionTypes.end()) {
vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str());
} else {
blog(LOG_WARNING, "ignored unknown streaming action %d",
static_cast<int>(_action));
}
}
bool MacroActionStream::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
obs_data_set_int(obj, "action", static_cast<int>(_action));
return true;
}
bool MacroActionStream::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_action = static_cast<StreamAction>(obs_data_get_int(obj, "action"));
return true;
}
static inline void populateActionSelection(QComboBox *list)
{
for (auto entry : actionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroActionStreamEdit::MacroActionStreamEdit(
QWidget *parent, std::shared_ptr<MacroActionStream> entryData)
: QWidget(parent)
{
_actions = new QComboBox();
populateActionSelection(_actions);
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
SLOT(ActionChanged(int)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{actions}}", _actions},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.streaming.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroActionStreamEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
}
void MacroActionStreamEdit::ActionChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_action = static_cast<StreamAction>(value);
}

View File

@@ -0,0 +1,73 @@
#include "headers/macro-action-switch-scene.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
const int MacroActionSwitchScene::id = 0;
bool MacroActionSwitchScene::_registered = MacroActionFactory::Register(
MacroActionSwitchScene::id,
{MacroActionSwitchScene::Create, MacroActionSwitchSceneEdit::Create,
"AdvSceneSwitcher.action.switchScene"});
bool MacroActionSwitchScene::PerformAction()
{
OBSWeakSource scene = getScene();
switchScene({scene, transition, (int)(_duration.seconds * 1000)});
return true;
}
void MacroActionSwitchScene::LogAction()
{
if (switcher->verbose) {
logMatch();
}
}
bool MacroActionSwitchScene::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
SceneSwitcherEntry::save(obj);
_duration.Save(obj);
return true;
}
bool MacroActionSwitchScene::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
SceneSwitcherEntry::load(obj);
_duration.Load(obj);
return true;
}
MacroActionSwitchSceneEdit::MacroActionSwitchSceneEdit(
QWidget *parent, std::shared_ptr<MacroActionSwitchScene> entryData)
: SwitchWidget(parent, entryData.get(), true, true)
{
_duration = new DurationSelection(parent, false);
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{scenes}}", scenes},
{"{{transitions}}", transitions},
{"{{duration}}", _duration},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.action.scene.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
_duration->SetDuration(_entryData->_duration);
SwitchWidget::loading = false;
}
void MacroActionSwitchSceneEdit::DurationChanged(double seconds)
{
if (SwitchWidget::loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}

206
src/macro-action-wait.cpp Normal file
View File

@@ -0,0 +1,206 @@
#include "headers/macro-action-wait.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
#include <random>
const int MacroActionWait::id = 1;
bool MacroActionWait::_registered = MacroActionFactory::Register(
MacroActionWait::id,
{MacroActionWait::Create, MacroActionWaitEdit::Create,
"AdvSceneSwitcher.action.wait"});
static std::map<WaitType, std::string> waitTypes = {
{WaitType::FIXED, "AdvSceneSwitcher.action.wait.type.fixed"},
{WaitType::RANDOM, "AdvSceneSwitcher.action.wait.type.random"},
};
static std::random_device rd;
static std::default_random_engine re(rd());
bool MacroActionWait::PerformAction()
{
double sleep_duration;
if (_waitType == WaitType::FIXED) {
sleep_duration = _duration.seconds;
} else {
double min = (_duration.seconds < _duration2.seconds)
? _duration.seconds
: _duration2.seconds;
double max = (_duration.seconds < _duration2.seconds)
? _duration2.seconds
: _duration.seconds;
std::uniform_real_distribution<double> unif(min, max);
sleep_duration = unif(re);
}
vblog(LOG_INFO, "perform action wait with duration of %f",
sleep_duration);
std::unique_lock<std::mutex> lock(switcher->m);
switcher->cv.wait_for(lock, std::chrono::milliseconds((
long long)(sleep_duration * 1000)));
return !switcher->stop;
}
bool MacroActionWait::Save(obs_data_t *obj)
{
MacroAction::Save(obj);
_duration.Save(obj);
_duration2.Save(obj, "seconds2", "displayUnit2");
obs_data_set_int(obj, "waitType", static_cast<int>(_waitType));
return true;
}
bool MacroActionWait::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_duration.Load(obj);
_duration2.Load(obj, "seconds2", "displayUnit2");
_waitType = static_cast<WaitType>(obs_data_get_int(obj, "waitType"));
return true;
}
static inline void populateTypeSelection(QComboBox *list)
{
for (auto entry : waitTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroActionWaitEdit::MacroActionWaitEdit(
QWidget *parent, std::shared_ptr<MacroActionWait> entryData)
: QWidget(parent)
{
_duration = new DurationSelection();
_duration2 = new DurationSelection();
_waitType = new QComboBox();
populateTypeSelection(_waitType);
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
QWidget::connect(_duration2, SIGNAL(DurationChanged(double)), this,
SLOT(Duration2Changed(double)));
QWidget::connect(_duration2, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(Duration2UnitChanged(DurationUnit)));
QWidget::connect(_waitType, SIGNAL(currentIndexChanged(int)), this,
SLOT(TypeChanged(int)));
_mainLayout = new QHBoxLayout;
setLayout(_mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroActionWaitEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
if (_entryData->_waitType == WaitType::FIXED) {
SetupFixedDurationEdit();
} else {
SetupRandomDurationEdit();
}
_duration->SetDuration(_entryData->_duration);
_duration2->SetDuration(_entryData->_duration2);
_waitType->setCurrentIndex(static_cast<int>(_entryData->_waitType));
}
void MacroActionWaitEdit::SetupFixedDurationEdit()
{
_mainLayout->removeWidget(_duration);
_mainLayout->removeWidget(_duration2);
_mainLayout->removeWidget(_waitType);
clearLayout(_mainLayout);
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{duration}}", _duration},
{"{{waitType}}", _waitType},
};
placeWidgets(
obs_module_text("AdvSceneSwitcher.action.wait.entry.fixed"),
_mainLayout, widgetPlaceholders);
_duration2->hide();
}
void MacroActionWaitEdit::SetupRandomDurationEdit()
{
_mainLayout->removeWidget(_duration);
_mainLayout->removeWidget(_duration2);
_mainLayout->removeWidget(_waitType);
clearLayout(_mainLayout);
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{duration}}", _duration},
{"{{duration2}}", _duration2},
{"{{waitType}}", _waitType},
};
placeWidgets(
obs_module_text("AdvSceneSwitcher.action.wait.entry.random"),
_mainLayout, widgetPlaceholders);
_duration2->show();
}
void MacroActionWaitEdit::TypeChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
WaitType type = static_cast<WaitType>(value);
if (type == WaitType::FIXED) {
SetupFixedDurationEdit();
} else {
SetupRandomDurationEdit();
}
_entryData->_waitType = type;
}
void MacroActionWaitEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroActionWaitEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroActionWaitEdit::Duration2Changed(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration2.seconds = seconds;
}
void MacroActionWaitEdit::Duration2UnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration2.displayUnit = unit;
}

View File

@@ -0,0 +1,239 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-audio.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionAudio::id = 3;
bool MacroConditionAudio::_registered = MacroConditionFactory::Register(
MacroConditionAudio::id,
{MacroConditionAudio::Create, MacroConditionAudioEdit::Create,
"AdvSceneSwitcher.condition.audio"});
static std::map<AudioCondition, std::string> audioConditionTypes = {
{AudioCondition::ABOVE, "AdvSceneSwitcher.ondition.audio.state.above"},
{AudioCondition::BELOW, "AdvSceneSwitcher.ondition.audio.state.below"},
};
MacroConditionAudio::~MacroConditionAudio()
{
obs_volmeter_remove_callback(_volmeter, SetVolumeLevel, this);
obs_volmeter_destroy(_volmeter);
}
bool MacroConditionAudio::CheckCondition()
{
// peak will have a value from -60 db to 0 db
bool volumeThresholdreached = false;
if (_condition == AudioCondition::ABOVE) {
volumeThresholdreached = ((double)_peak + 60) * 1.7 > _volume;
} else {
volumeThresholdreached = ((double)_peak + 60) * 1.7 < _volume;
}
// Reset for next check
_peak = -std::numeric_limits<float>::infinity();
if (!volumeThresholdreached) {
_duration.Reset();
return false;
}
return _duration.DurationReached();
}
bool MacroConditionAudio::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "audioSource",
GetWeakSourceName(_audioSource).c_str());
obs_data_set_int(obj, "volume", _volume);
obs_data_set_int(obj, "condition", static_cast<int>(_condition));
_duration.Save(obj);
return true;
}
obs_volmeter_t *AddVolmeterToSource(MacroConditionAudio *entry,
obs_weak_source *source)
{
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);
blog(LOG_WARNING, "failed to attach volmeter to source %s",
name);
}
obs_source_release(as);
return volmeter;
}
bool MacroConditionAudio::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
const char *audioSourceName = obs_data_get_string(obj, "audioSource");
_audioSource = GetWeakSourceByName(audioSourceName);
_volume = obs_data_get_int(obj, "volume");
_condition =
static_cast<AudioCondition>(obs_data_get_int(obj, "condition"));
_duration.Load(obj);
_volmeter = AddVolmeterToSource(this, _audioSource);
return true;
}
void MacroConditionAudio::SetVolumeLevel(
void *data, const float magnitude[MAX_AUDIO_CHANNELS],
const float peak[MAX_AUDIO_CHANNELS],
const float inputPeak[MAX_AUDIO_CHANNELS])
{
UNUSED_PARAMETER(magnitude);
UNUSED_PARAMETER(inputPeak);
MacroConditionAudio *c = static_cast<MacroConditionAudio *>(data);
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++) {
if (peak[i] > c->_peak) {
c->_peak = peak[i];
}
}
}
void MacroConditionAudio::ResetVolmeter()
{
obs_volmeter_remove_callback(_volmeter, SetVolumeLevel, this);
obs_volmeter_destroy(_volmeter);
_volmeter = AddVolmeterToSource(this, _audioSource);
}
static inline void populateConditionSelection(QComboBox *list)
{
for (auto entry : audioConditionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionAudioEdit::MacroConditionAudioEdit(
QWidget *parent, std::shared_ptr<MacroConditionAudio> entryData)
: QWidget(parent)
{
_audioSources = new QComboBox();
_condition = new QComboBox();
_volume = new QSpinBox();
_duration = new DurationSelection(parent, false);
_volume->setSuffix("%");
_volume->setMaximum(100);
_volume->setMinimum(0);
QWidget::connect(_volume, SIGNAL(valueChanged(int)), this,
SLOT(VolumeThresholdChanged(int)));
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this,
SLOT(ConditionChanged(int)));
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_audioSources,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SourceChanged(const QString &)));
AdvSceneSwitcher::populateAudioSelection(_audioSources);
populateConditionSelection(_condition);
QHBoxLayout *switchLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{audioSources}}", _audioSources},
{"{{volume}}", _volume},
{"{{condition}}", _condition},
{"{{duration}}", _duration}};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.audio.entry"),
switchLayout, widgetPlaceholders);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(switchLayout);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionAudioEdit::UpdateVolmeterSource()
{
delete _volMeter;
obs_source_t *soruce =
obs_weak_source_get_source(_entryData->_audioSource);
_volMeter = new VolControl(soruce);
obs_source_release(soruce);
QLayout *layout = this->layout();
layout->addWidget(_volMeter);
QWidget::connect(_volMeter->GetSlider(), SIGNAL(valueChanged(int)),
_volume, SLOT(setValue(int)));
QWidget::connect(_volume, SIGNAL(valueChanged(int)),
_volMeter->GetSlider(), SLOT(setValue(int)));
// Slider will default to 0 so set it manually once
_volMeter->GetSlider()->setValue(_entryData->_volume);
}
void MacroConditionAudioEdit::SourceChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_audioSource = GetWeakSourceByQString(text);
_entryData->ResetVolmeter();
UpdateVolmeterSource();
}
void MacroConditionAudioEdit::VolumeThresholdChanged(int vol)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_volume = vol;
}
void MacroConditionAudioEdit::ConditionChanged(int cond)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_condition = static_cast<AudioCondition>(cond);
}
void MacroConditionAudioEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionAudioEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_audioSources->setCurrentText(
GetWeakSourceName(_entryData->_audioSource).c_str());
_volume->setValue(_entryData->_volume);
_condition->setCurrentIndex(static_cast<int>(_entryData->_condition));
_duration->SetDuration(_entryData->_duration);
UpdateVolmeterSource();
}

View File

@@ -0,0 +1,194 @@
#include "headers/macro-condition-edit.hpp"
std::map<int, MacroConditionInfo> MacroConditionFactory::_methods;
bool MacroConditionFactory::Register(int id, MacroConditionInfo info)
{
if (auto it = _methods.find(id); it == _methods.end()) {
_methods[id] = info;
return true;
}
return false;
}
std::shared_ptr<MacroCondition> MacroConditionFactory::Create(const int id)
{
if (auto it = _methods.find(id); it != _methods.end())
return it->second._createFunc();
return nullptr;
}
QWidget *
MacroConditionFactory::CreateWidget(const int id, QWidget *parent,
std::shared_ptr<MacroCondition> cond)
{
if (auto it = _methods.find(id); it != _methods.end())
return it->second._createWidgetFunc(parent, cond);
return nullptr;
}
static inline void populateLogicSelection(QComboBox *list, bool root = false)
{
if (root) {
for (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) {
if (static_cast<int>(entry.first) >=
logic_root_offset) {
list->addItem(obs_module_text(
entry.second._name.c_str()));
}
}
}
}
static inline void populateConditionSelection(QComboBox *list)
{
for (auto entry : MacroConditionFactory::GetConditionTypes()) {
list->addItem(obs_module_text(entry.second._name.c_str()));
}
}
MacroConditionEdit::MacroConditionEdit(
QWidget *parent, std::shared_ptr<MacroCondition> *entryData, int type,
bool root, bool startCollapsed)
: QWidget(parent)
{
_logicSelection = new QComboBox();
_conditionSelection = new QComboBox();
_section = new Section(300);
QWidget::connect(_logicSelection, SIGNAL(currentIndexChanged(int)),
this, SLOT(LogicSelectionChanged(int)));
QWidget::connect(_conditionSelection, SIGNAL(currentIndexChanged(int)),
this, SLOT(ConditionSelectionChanged(int)));
populateLogicSelection(_logicSelection, root);
populateConditionSelection(_conditionSelection);
_section->AddHeaderWidget(_logicSelection);
_section->AddHeaderWidget(_conditionSelection);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(_section);
setLayout(mainLayout);
_entryData = entryData;
_isRoot = root;
UpdateEntryData(type);
_loading = false;
_section->Collapse(startCollapsed);
}
void MacroConditionEdit::LogicSelectionChanged(int idx)
{
if (_loading || !_entryData) {
return;
}
LogicType type;
if (IsRootNode()) {
type = static_cast<LogicType>(idx);
} else {
type = static_cast<LogicType>(idx + logic_root_offset);
}
std::lock_guard<std::mutex> lock(switcher->m);
(*_entryData)->SetLogicType(type);
}
bool MacroConditionEdit::IsRootNode()
{
return _isRoot;
}
void MacroConditionEdit::UpdateEntryData(int type)
{
_conditionSelection->setCurrentIndex(type);
auto widget = MacroConditionFactory::CreateWidget(type, window(),
*_entryData);
auto logic = (*_entryData)->GetLogicType();
if (IsRootNode()) {
_logicSelection->setCurrentIndex(static_cast<int>(logic));
} else {
_logicSelection->setCurrentIndex(static_cast<int>(logic) -
logic_root_offset);
}
_section->SetContent(widget);
}
void MacroConditionEdit::Collapse(bool collapsed)
{
_section->Collapse(collapsed);
}
void MacroConditionEdit::ConditionSelectionChanged(int idx)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
auto logic = (*_entryData)->GetLogicType();
_entryData->reset();
*_entryData = MacroConditionFactory::Create(idx);
(*_entryData)->SetLogicType(logic);
auto widget =
MacroConditionFactory::CreateWidget(idx, window(), *_entryData);
_section->SetContent(widget);
_section->Collapse(false);
}
void AdvSceneSwitcher::on_conditionAdd_clicked()
{
auto macro = getSelectedMacro();
if (!macro) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
bool root = macro->Conditions().size() == 0;
macro->Conditions().emplace_back(MacroConditionFactory::Create(0));
auto logic = root ? LogicType::ROOT_NONE : LogicType::NONE;
macro->Conditions().back()->SetLogicType(logic);
auto newEntry = new MacroConditionEdit(
this, &macro->Conditions().back(), 0, root);
ui->macroEditConditionLayout->addWidget(newEntry);
ui->macroEditConditionHelp->setVisible(false);
newEntry->Collapse(false);
}
void AdvSceneSwitcher::on_conditionRemove_clicked()
{
auto macro = getSelectedMacro();
if (!macro) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (macro->Conditions().empty()) {
return;
}
macro->Conditions().pop_back();
int count = ui->macroEditConditionLayout->count();
auto item = ui->macroEditConditionLayout->takeAt(count - 1);
if (item) {
auto widget = item->widget();
if (widget) {
widget->setVisible(false);
}
delete item;
}
if (count == 1) {
ui->macroEditConditionHelp->setVisible(true);
}
}

View File

@@ -0,0 +1,293 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-file.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/curl-helper.hpp"
#include <QTextStream>
#include <QFileDialog>
const int MacroConditionFile::id = 4;
bool MacroConditionFile::_registered = MacroConditionFactory::Register(
MacroConditionFile::id,
{MacroConditionFile::Create, MacroConditionFileEdit::Create,
"AdvSceneSwitcher.condition.file"});
static std::hash<std::string> strHash;
static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
void *userp)
{
((std::string *)userp)->append((char *)contents, size * nmemb);
return size * nmemb;
}
static std::string getRemoteData(std::string &url)
{
std::string readBuffer;
if (switcher->curl && f_curl_setopt && f_curl_perform) {
f_curl_setopt(switcher->curl, CURLOPT_URL, url.c_str());
f_curl_setopt(switcher->curl, CURLOPT_WRITEFUNCTION,
WriteCallback);
f_curl_setopt(switcher->curl, CURLOPT_WRITEDATA, &readBuffer);
f_curl_perform(switcher->curl);
}
return readBuffer;
}
bool MacroConditionFile::matchFileContent(QString &filedata)
{
if (_onlyMatchIfChanged) {
size_t newHash = strHash(filedata.toUtf8().constData());
if (newHash == _lastHash) {
return false;
}
_lastHash = newHash;
}
if (_useRegex) {
QRegExp rx(QString::fromStdString(_text));
return rx.exactMatch(filedata);
}
QString text = QString::fromStdString(_text);
return compareIgnoringLineEnding(text, filedata);
}
bool MacroConditionFile::checkRemoteFileContent()
{
std::string data = getRemoteData(_file);
QString qdata = QString::fromStdString(data);
return matchFileContent(qdata);
}
bool MacroConditionFile::checkLocalFileContent()
{
QString t = QString::fromStdString(_text);
QFile file(QString::fromStdString(_file));
if (_file.empty() || !file.open(QIODevice::ReadOnly)) {
return false;
}
if (_useTime) {
QDateTime newLastMod = QFileInfo(file).lastModified();
if (_lastMod == newLastMod) {
return false;
}
_lastMod = newLastMod;
}
QString filedata = QTextStream(&file).readAll();
bool match = matchFileContent(filedata);
file.close();
return match;
}
bool MacroConditionFile::CheckCondition()
{
if (_fileType == FileType::REMOTE) {
return checkRemoteFileContent();
} else {
return checkLocalFileContent();
}
}
bool MacroConditionFile::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "file", _file.c_str());
obs_data_set_string(obj, "text", _text.c_str());
obs_data_set_int(obj, "fileType", static_cast<int>(_fileType));
obs_data_set_bool(obj, "useRegex", _useRegex);
obs_data_set_bool(obj, "useTime", _useTime);
obs_data_set_bool(obj, "onlyMatchIfChanged", _onlyMatchIfChanged);
return true;
}
bool MacroConditionFile::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_file = obs_data_get_string(obj, "file");
_text = obs_data_get_string(obj, "text");
_fileType = static_cast<FileType>(obs_data_get_int(obj, "fileType"));
_useRegex = obs_data_get_bool(obj, "useRegex");
_useTime = obs_data_get_bool(obj, "useTime");
_onlyMatchIfChanged = obs_data_get_bool(obj, "onlyMatchIfChanged");
return true;
}
MacroConditionFileEdit::MacroConditionFileEdit(
QWidget *parent, std::shared_ptr<MacroConditionFile> entryData)
: QWidget(parent)
{
_fileType = new QComboBox();
_filePath = new QLineEdit();
_browseButton =
new QPushButton(obs_module_text("AdvSceneSwitcher.browse"));
_browseButton->setStyleSheet("border:1px solid gray;");
_matchText = new QPlainTextEdit();
_useRegex = new QCheckBox(
obs_module_text("AdvSceneSwitcher.fileTab.useRegExp"));
_checkModificationDate = new QCheckBox(obs_module_text(
"AdvSceneSwitcher.fileTab.checkfileContentTime"));
_checkFileContent = new QCheckBox(
obs_module_text("AdvSceneSwitcher.fileTab.checkfileContent"));
QWidget::connect(_fileType, SIGNAL(currentIndexChanged(int)), this,
SLOT(FileTypeChanged(int)));
QWidget::connect(_filePath, SIGNAL(editingFinished()), this,
SLOT(FilePathChanged()));
QWidget::connect(_browseButton, SIGNAL(clicked()), this,
SLOT(BrowseButtonClicked()));
QWidget::connect(_matchText, SIGNAL(textChanged()), this,
SLOT(MatchTextChanged()));
QWidget::connect(_useRegex, SIGNAL(stateChanged(int)), this,
SLOT(UseRegexChanged(int)));
QWidget::connect(_checkModificationDate, SIGNAL(stateChanged(int)),
this, SLOT(CheckModificationDateChanged(int)));
QWidget::connect(_checkFileContent, SIGNAL(stateChanged(int)), this,
SLOT(OnlyMatchIfChangedChanged(int)));
_fileType->addItem(obs_module_text("AdvSceneSwitcher.fileTab.local"));
_fileType->addItem(obs_module_text("AdvSceneSwitcher.fileTab.remote"));
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{fileType}}", _fileType},
{"{{filePath}}", _filePath},
{"{{browseButton}}", _browseButton},
{"{{matchText}}", _matchText},
{"{{useRegex}}", _useRegex},
{"{{checkModificationDate}}", _checkModificationDate},
{"{{checkFileContent}}", _checkFileContent},
};
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *line1Layout = new QHBoxLayout;
QHBoxLayout *line2Layout = new QHBoxLayout;
QHBoxLayout *line3Layout = new QHBoxLayout;
placeWidgets(
obs_module_text("AdvSceneSwitcher.condition.file.entry.line1"),
line1Layout, widgetPlaceholders);
placeWidgets(
obs_module_text("AdvSceneSwitcher.condition.file.entry.line2"),
line2Layout, widgetPlaceholders, false);
placeWidgets(
obs_module_text("AdvSceneSwitcher.condition.file.entry.line3"),
line3Layout, widgetPlaceholders);
mainLayout->addLayout(line1Layout);
mainLayout->addLayout(line2Layout);
mainLayout->addLayout(line3Layout);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionFileEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_fileType->setCurrentIndex(static_cast<int>(_entryData->_fileType));
_filePath->setText(QString::fromStdString(_entryData->_file));
_matchText->setPlainText(QString::fromStdString(_entryData->_text));
_useRegex->setChecked(_entryData->_useRegex);
_checkModificationDate->setChecked(_entryData->_useTime);
_checkFileContent->setChecked(_entryData->_onlyMatchIfChanged);
}
void MacroConditionFileEdit::FileTypeChanged(int index)
{
if (_loading || !_entryData) {
return;
}
FileType type = static_cast<FileType>(index);
if (type == FileType::LOCAL) {
_browseButton->setDisabled(false);
_checkModificationDate->setDisabled(false);
} else {
_browseButton->setDisabled(true);
_checkModificationDate->setDisabled(true);
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_fileType = type;
}
void MacroConditionFileEdit::FilePathChanged()
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_file = _filePath->text().toUtf8().constData();
}
void MacroConditionFileEdit::BrowseButtonClicked()
{
if (_loading || !_entryData) {
return;
}
QString path = QFileDialog::getOpenFileName(
this,
tr(obs_module_text("AdvSceneSwitcher.fileTab.selectRead")),
QDir::currentPath(),
tr(obs_module_text("AdvSceneSwitcher.fileTab.anyFileType")));
if (path.isEmpty()) {
return;
}
_filePath->setText(path);
FilePathChanged();
}
void MacroConditionFileEdit::MatchTextChanged()
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_text = _matchText->toPlainText().toUtf8().constData();
}
void MacroConditionFileEdit::UseRegexChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_useRegex = state;
}
void MacroConditionFileEdit::CheckModificationDateChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_useTime = state;
}
void MacroConditionFileEdit::OnlyMatchIfChangedChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_onlyMatchIfChanged = state;
}

View File

@@ -0,0 +1,83 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-idle.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionIdle::id = 10;
bool MacroConditionIdle::_registered = MacroConditionFactory::Register(
MacroConditionIdle::id,
{MacroConditionIdle::Create, MacroConditionIdleEdit::Create,
"AdvSceneSwitcher.condition.idle"});
bool MacroConditionIdle::CheckCondition()
{
return secondsSinceLastInput() >= _duration.seconds;
}
bool MacroConditionIdle::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
_duration.Save(obj);
return true;
}
bool MacroConditionIdle::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_duration.Load(obj);
return true;
}
MacroConditionIdleEdit::MacroConditionIdleEdit(
QWidget *parent, std::shared_ptr<MacroConditionIdle> entryData)
: QWidget(parent)
{
_duration = new DurationSelection();
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{duration}}", _duration},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.idle.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionIdleEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionIdleEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroConditionIdleEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_duration->SetDuration(_entryData->_duration);
}

View File

@@ -0,0 +1,376 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-media.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionMedia::id = 5;
bool MacroConditionMedia::_registered = MacroConditionFactory::Register(
MacroConditionMedia::id,
{MacroConditionMedia::Create, MacroConditionMediaEdit::Create,
"AdvSceneSwitcher.condition.media"});
static std::map<MediaTimeRestriction, std::string> mediaTimeRestrictions = {
{MediaTimeRestriction::TIME_RESTRICTION_NONE,
"AdvSceneSwitcher.mediaTab.timeRestriction.none"},
{MediaTimeRestriction::TIME_RESTRICTION_SHORTER,
"AdvSceneSwitcher.mediaTab.timeRestriction.shorter"},
{MediaTimeRestriction::TIME_RESTRICTION_LONGER,
"AdvSceneSwitcher.mediaTab.timeRestriction.longer"},
{MediaTimeRestriction::TIME_RESTRICTION_REMAINING_SHORTER,
"AdvSceneSwitcher.mediaTab.timeRestriction.remainShorter"},
{MediaTimeRestriction::TIME_RESTRICTION_REMAINING_LONGER,
"AdvSceneSwitcher.mediaTab.timeRestriction.remainLonger"},
};
static std::map<MediaState, std::string> mediaStates = {
{MediaState::OBS_MEDIA_STATE_NONE,
"AdvSceneSwitcher.mediaTab.states.none"},
{MediaState::OBS_MEDIA_STATE_PLAYING,
"AdvSceneSwitcher.mediaTab.states.playing"},
{MediaState::OBS_MEDIA_STATE_OPENING,
"AdvSceneSwitcher.mediaTab.states.opening"},
{MediaState::OBS_MEDIA_STATE_BUFFERING,
"AdvSceneSwitcher.mediaTab.states.buffering"},
{MediaState::OBS_MEDIA_STATE_PAUSED,
"AdvSceneSwitcher.mediaTab.states.paused"},
{MediaState::OBS_MEDIA_STATE_STOPPED,
"AdvSceneSwitcher.mediaTab.states.stopped"},
{MediaState::OBS_MEDIA_STATE_ENDED,
"AdvSceneSwitcher.mediaTab.states.ended"},
{MediaState::OBS_MEDIA_STATE_ERROR,
"AdvSceneSwitcher.mediaTab.states.error"},
{MediaState::PLAYED_TO_END,
"AdvSceneSwitcher.mediaTab.states.playedToEnd"},
{MediaState::ANY, "AdvSceneSwitcher.mediaTab.states.any"},
};
MacroConditionMedia::~MacroConditionMedia()
{
obs_source_t *mediasource = obs_weak_source_get_source(_source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_disconnect(sh, "media_stopped", MediaStopped, this);
signal_handler_disconnect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
}
bool matchTime(const int64_t currentTime, const int64_t duration,
const MediaTimeRestriction restriction, const int64_t time)
{
bool matchedTimeNone =
(restriction == MediaTimeRestriction::TIME_RESTRICTION_NONE);
bool matchedTimeLonger =
(restriction ==
MediaTimeRestriction::TIME_RESTRICTION_LONGER) &&
(currentTime > time);
bool matchedTimeShorter =
(restriction ==
MediaTimeRestriction::TIME_RESTRICTION_SHORTER) &&
(currentTime < time);
bool matchedTimeRemainLonger =
(restriction ==
MediaTimeRestriction::TIME_RESTRICTION_REMAINING_LONGER) &&
(duration > currentTime && duration - currentTime > time);
bool matchedTimeRemainShorter =
(restriction ==
MediaTimeRestriction::TIME_RESTRICTION_REMAINING_SHORTER) &&
(duration > currentTime && duration - currentTime < time);
return matchedTimeNone || matchedTimeLonger || matchedTimeShorter ||
matchedTimeRemainLonger || matchedTimeRemainShorter;
}
bool MacroConditionMedia::CheckCondition()
{
if (!_source) {
return false;
}
bool match = false;
obs_source_t *source = obs_weak_source_get_source(_source);
auto duration = obs_source_media_get_duration(source);
auto time = obs_source_media_get_time(source);
obs_media_state currentState = obs_source_media_get_state(source);
obs_source_release(source);
// To be able to compare to obs_media_state more easily
int expectedState = static_cast<int>(_state);
bool matchedStopped = expectedState == OBS_MEDIA_STATE_STOPPED &&
_stopped;
// The signal for the state ended is intentionally not used here
// so matchedEnded can be used to specify the end of a VLC playlist
// by two consequtive matches of OBS_MEDIA_STATE_ENDED
//
// This was done to reduce the likelyhood of interpreting a single
// OBS_MEDIA_STATE_ENDED caught by obs_source_media_get_state()
// as the end of the playlist of the VLC source, while actually being
// in the middle of switching to the next item of the playlist
//
// If there is a separate obs_media_sate in the future for the
// "end of playlist reached" signal the line below can be used
// and an additional check for this new singal can be introduced
//
// bool matchedEnded = _state == OBS_MEDIA_STATE_ENDED && _ended;
bool ended = false;
if (currentState == OBS_MEDIA_STATE_ENDED) {
ended = _previousStateEnded;
_previousStateEnded = true;
} else {
_previousStateEnded = false;
}
bool matchedEnded = ended && (expectedState == OBS_MEDIA_STATE_ENDED);
// match if playedToEnd was true in last interval
// and playback is currently ended
bool matchedPlayedToEnd = _state == MediaState::PLAYED_TO_END &&
_playedToEnd && ended;
// interval * 2 to make sure not to miss any state changes
// which happened during check of the conditions
_playedToEnd = _playedToEnd ||
(duration - time <= switcher->interval * 2);
// reset for next check
if (ended) {
_playedToEnd = false;
}
_stopped = false;
_ended = false;
bool matchedState =
(currentState == expectedState || _state == MediaState::ANY) ||
matchedStopped || matchedEnded || matchedPlayedToEnd;
bool matchedTime =
matchTime(time, duration, _restriction, _time.seconds * 1000);
bool matched = matchedState && matchedTime;
if (matched && !_alreadyMatched) {
match = true;
}
_alreadyMatched = matched;
return match;
}
bool MacroConditionMedia::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "source", GetWeakSourceName(_source).c_str());
obs_data_set_int(obj, "state", static_cast<int>(_state));
obs_data_set_int(obj, "restriction", static_cast<int>(_restriction));
_time.Save(obj);
return true;
}
bool MacroConditionMedia::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
const char *sourceName = obs_data_get_string(obj, "source");
_source = GetWeakSourceByName(sourceName);
_state = static_cast<MediaState>(obs_data_get_int(obj, "state"));
_restriction = static_cast<MediaTimeRestriction>(
obs_data_get_int(obj, "restriction"));
_time.Load(obj);
obs_source_t *mediasource = obs_weak_source_get_source(_source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_connect(sh, "media_stopped", MediaStopped, this);
signal_handler_connect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
return true;
}
void MacroConditionMedia::ClearSignalHandler()
{
obs_source_t *mediasource = obs_weak_source_get_source(_source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_disconnect(sh, "media_stopped", MediaStopped, this);
signal_handler_disconnect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
}
void MacroConditionMedia::ResetSignalHandler()
{
obs_source_t *mediasource = obs_weak_source_get_source(_source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_disconnect(sh, "media_stopped", MediaStopped, this);
signal_handler_disconnect(sh, "media_ended", MediaEnded, this);
signal_handler_connect(sh, "media_stopped", MediaStopped, this);
signal_handler_connect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
}
void MacroConditionMedia::MediaStopped(void *data, calldata_t *)
{
MacroConditionMedia *media = static_cast<MacroConditionMedia *>(data);
media->_stopped = true;
}
void MacroConditionMedia::MediaEnded(void *data, calldata_t *)
{
MacroConditionMedia *media = static_cast<MacroConditionMedia *>(data);
media->_ended = true;
}
static void populateMediaTimeRestrictions(QComboBox *list)
{
for (auto entry : mediaTimeRestrictions) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
static void populateMediaStates(QComboBox *list)
{
for (auto entry : mediaStates) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionMediaEdit::MacroConditionMediaEdit(
QWidget *parent, std::shared_ptr<MacroConditionMedia> entryData)
: QWidget(parent)
{
_mediaSources = new QComboBox();
_states = new QComboBox();
_timeRestrictions = new QComboBox();
_time = new DurationSelection();
QWidget::connect(_mediaSources,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SourceChanged(const QString &)));
QWidget::connect(_states, SIGNAL(currentIndexChanged(int)), this,
SLOT(StateChanged(int)));
QWidget::connect(_timeRestrictions, SIGNAL(currentIndexChanged(int)),
this, SLOT(TimeRestrictionChanged(int)));
QWidget::connect(_time, SIGNAL(DurationChanged(double)), this,
SLOT(TimeChanged(double)));
QWidget::connect(_time, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(TimeUnitChanged(DurationUnit)));
AdvSceneSwitcher::populateMediaSelection(_mediaSources);
populateMediaStates(_states);
populateMediaTimeRestrictions(_timeRestrictions);
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{mediaSources}}", _mediaSources},
{"{{states}}", _states},
{"{{timeRestrictions}}", _timeRestrictions},
{"{{time}}", _time},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.media.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionMediaEdit::SourceChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->ClearSignalHandler();
_entryData->_source = GetWeakSourceByQString(text);
_entryData->ResetSignalHandler();
}
MediaState getMediaStateFromIdx(int idx)
{
if (idx < static_cast<int>(MediaState::LAST_OBS_MEDIA_STATE)) {
return static_cast<MediaState>(idx);
} else {
return static_cast<MediaState>(
idx -
static_cast<int>(MediaState::LAST_OBS_MEDIA_STATE) +
custom_media_states_offset);
}
}
void MacroConditionMediaEdit::StateChanged(int index)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_state = getMediaStateFromIdx(index);
}
void MacroConditionMediaEdit::TimeRestrictionChanged(int index)
{
if (_loading || !_entryData) {
return;
}
if (static_cast<MediaTimeRestriction>(index) ==
MediaTimeRestriction::TIME_RESTRICTION_NONE) {
_time->setDisabled(true);
} else {
_time->setDisabled(false);
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_restriction = static_cast<MediaTimeRestriction>(index);
}
void MacroConditionMediaEdit::TimeChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_time.seconds = seconds;
}
void MacroConditionMediaEdit::TimeUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_time.displayUnit = unit;
}
int getIdxFromMediaState(MediaState state)
{
if (state < MediaState::LAST_OBS_MEDIA_STATE) {
return static_cast<int>(state);
} else {
return static_cast<int>(state) - custom_media_states_offset +
static_cast<int>(MediaState::LAST_OBS_MEDIA_STATE);
}
}
void MacroConditionMediaEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_mediaSources->setCurrentText(
GetWeakSourceName(_entryData->_source).c_str());
_states->setCurrentIndex(getIdxFromMediaState(_entryData->_state));
_timeRestrictions->setCurrentIndex(
static_cast<int>(_entryData->_restriction));
_time->SetDuration(_entryData->_time);
if (_entryData->_restriction ==
MediaTimeRestriction::TIME_RESTRICTION_NONE) {
_time->setDisabled(true);
}
}

View File

@@ -0,0 +1,92 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-plugin-state.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionPluginState::id = 11;
bool MacroConditionPluginState::_registered = MacroConditionFactory::Register(
MacroConditionPluginState::id,
{MacroConditionPluginState::Create,
MacroConditionPluginStateEdit::Create,
"AdvSceneSwitcher.condition.pluginState"});
static std::map<PluginStateCondition, std::string> pluginStateConditionTypes = {
{PluginStateCondition::SCENESWITCHED,
"AdvSceneSwitcher.condition.pluginState.state.sceneSwitched"},
};
bool MacroConditionPluginState::CheckCondition()
{
return switcher->macroSceneSwitched;
}
bool MacroConditionPluginState::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_int(obj, "condition", static_cast<int>(_condition));
return true;
}
bool MacroConditionPluginState::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_condition = static_cast<PluginStateCondition>(
obs_data_get_int(obj, "condition"));
return true;
}
static inline void populateConditionSelection(QComboBox *list)
{
for (auto entry : pluginStateConditionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionPluginStateEdit::MacroConditionPluginStateEdit(
QWidget *parent, std::shared_ptr<MacroConditionPluginState> entryData)
: QWidget(parent)
{
_condition = new QComboBox();
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this,
SLOT(ConditionChanged(int)));
populateConditionSelection(_condition);
QHBoxLayout *switchLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{condition}}", _condition},
};
placeWidgets(
obs_module_text("AdvSceneSwitcher.condition.pluginState.entry"),
switchLayout, widgetPlaceholders);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(switchLayout);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionPluginStateEdit::ConditionChanged(int cond)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_condition = static_cast<PluginStateCondition>(cond);
}
void MacroConditionPluginStateEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_condition->setCurrentIndex(static_cast<int>(_entryData->_condition));
}

View File

@@ -0,0 +1,110 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-process.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include <regex>
const int MacroConditionProcess::id = 9;
bool MacroConditionProcess::_registered = MacroConditionFactory::Register(
MacroConditionProcess::id,
{MacroConditionProcess::Create, MacroConditionProcessEdit::Create,
"AdvSceneSwitcher.condition.process"});
bool MacroConditionProcess::CheckCondition()
{
std::string title;
QStringList runningProcesses;
QString proc = QString::fromStdString(_process);
GetCurrentWindowTitle(title);
GetProcessList(runningProcesses);
bool equals = runningProcesses.contains(proc);
bool matches = runningProcesses.indexOf(QRegularExpression(proc)) != -1;
bool focus = !_focus || isInFocus(proc);
return (equals || matches) && focus;
}
bool MacroConditionProcess::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "process", _process.c_str());
obs_data_set_bool(obj, "focus", _focus);
return true;
}
bool MacroConditionProcess::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_process = obs_data_get_string(obj, "process");
_focus = obs_data_get_bool(obj, "focus");
return true;
}
MacroConditionProcessEdit::MacroConditionProcessEdit(
QWidget *parent, std::shared_ptr<MacroConditionProcess> entryData)
: QWidget(parent)
{
_processSelection = new QComboBox();
_processSelection->setEditable(true);
_processSelection->setMaxVisibleItems(20);
_focused = new QCheckBox();
QWidget::connect(_processSelection,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(ProcessChanged(const QString &)));
QWidget::connect(_focused, SIGNAL(stateChanged(int)), this,
SLOT(FocusChanged(int)));
AdvSceneSwitcher::populateProcessSelection(_processSelection);
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{processes}}", _processSelection},
{"{{focused}}", _focused},
};
QHBoxLayout *mainLayout = new QHBoxLayout;
placeWidgets(
obs_module_text("AdvSceneSwitcher.condition.process.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionProcessEdit::ProcessChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_process = text.toStdString();
}
void MacroConditionProcessEdit::FocusChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_focus = state;
}
void MacroConditionProcessEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_processSelection->setCurrentText(_entryData->_process.c_str());
_focused->setChecked(_entryData->_focus);
}

View File

@@ -0,0 +1,138 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-recording.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionRecord::id = 8;
bool MacroConditionRecord::_registered = MacroConditionFactory::Register(
MacroConditionRecord::id,
{MacroConditionRecord::Create, MacroConditionRecordEdit::Create,
"AdvSceneSwitcher.condition.record"});
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"},
};
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;
default:
break;
}
if (!stateMatch) {
_duration.Reset();
return false;
}
return _duration.DurationReached();
}
bool MacroConditionRecord::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_int(obj, "state", static_cast<int>(_recordState));
_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"));
_duration.Load(obj);
return true;
}
static inline void populateStateSelection(QComboBox *list)
{
for (auto entry : recordStates) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionRecordEdit::MacroConditionRecordEdit(
QWidget *parent, std::shared_ptr<MacroConditionRecord> entryData)
: QWidget(parent)
{
_recordState = new QComboBox();
_duration = new DurationSelection();
QWidget::connect(_recordState, SIGNAL(currentIndexChanged(int)), this,
SLOT(StateChanged(int)));
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
populateStateSelection(_recordState);
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{recordState}}", _recordState},
{"{{duration}}", _duration},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.record.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionRecordEdit::StateChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_recordState = static_cast<RecordState>(value);
}
void MacroConditionRecordEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionRecordEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroConditionRecordEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_recordState->setCurrentIndex(
static_cast<int>(_entryData->_recordState));
_duration->SetDuration(_entryData->_duration);
}

View File

@@ -0,0 +1,140 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-region.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionRegion::id = 2;
bool MacroConditionRegion::_registered = MacroConditionFactory::Register(
MacroConditionRegion::id,
{MacroConditionRegion::Create, MacroConditionRegionEdit::Create,
"AdvSceneSwitcher.condition.region"});
bool MacroConditionRegion::CheckCondition()
{
std::pair<int, int> cursorPos = getCursorPos();
return cursorPos.first >= _minX && cursorPos.second >= _minY &&
cursorPos.first <= _maxX && cursorPos.second <= _maxY;
}
bool MacroConditionRegion::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_int(obj, "minX", _minX);
obs_data_set_int(obj, "minY", _minY);
obs_data_set_int(obj, "maxX", _maxX);
obs_data_set_int(obj, "maxY", _maxY);
return true;
}
bool MacroConditionRegion::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_minX = obs_data_get_int(obj, "minX");
_minY = obs_data_get_int(obj, "minY");
_maxX = obs_data_get_int(obj, "maxX");
_maxY = obs_data_get_int(obj, "maxY");
return true;
}
MacroConditionRegionEdit::MacroConditionRegionEdit(
QWidget *parent, std::shared_ptr<MacroConditionRegion> entryData)
: QWidget(parent)
{
_minX = new QSpinBox();
_minY = new QSpinBox();
_maxX = new QSpinBox();
_maxY = new QSpinBox();
_minX->setPrefix("Min X: ");
_minY->setPrefix("Min Y: ");
_maxX->setPrefix("Max X: ");
_maxY->setPrefix("Max Y: ");
_minX->setMinimum(-1000000);
_minY->setMinimum(-1000000);
_maxX->setMinimum(-1000000);
_maxY->setMinimum(-1000000);
_minX->setMaximum(1000000);
_minY->setMaximum(1000000);
_maxX->setMaximum(1000000);
_maxY->setMaximum(1000000);
QWidget::connect(_minX, SIGNAL(valueChanged(int)), this,
SLOT(MinXChanged(int)));
QWidget::connect(_minY, SIGNAL(valueChanged(int)), this,
SLOT(MinYChanged(int)));
QWidget::connect(_maxX, SIGNAL(valueChanged(int)), this,
SLOT(MaxXChanged(int)));
QWidget::connect(_maxY, SIGNAL(valueChanged(int)), this,
SLOT(MaxYChanged(int)));
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{minX}}", _minX},
{"{{minY}}", _minY},
{"{{maxX}}", _maxX},
{"{{maxY}}", _maxY}};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.region.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionRegionEdit::MinXChanged(int pos)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_minX = pos;
}
void MacroConditionRegionEdit::MinYChanged(int pos)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_minY = pos;
}
void MacroConditionRegionEdit::MaxXChanged(int pos)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_maxX = pos;
}
void MacroConditionRegionEdit::MaxYChanged(int pos)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_maxY = pos;
}
void MacroConditionRegionEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_minX->setValue(_entryData->_minX);
_minY->setValue(_entryData->_minY);
_maxX->setValue(_entryData->_maxX);
_maxY->setValue(_entryData->_maxY);
}

View File

@@ -0,0 +1,150 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-scene.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionScene::id = 0;
bool MacroConditionScene::_registered = MacroConditionFactory::Register(
MacroConditionScene::id,
{MacroConditionScene::Create, MacroConditionSceneEdit::Create,
"AdvSceneSwitcher.condition.scene"});
static std::map<SceneType, std::string> sceneTypes = {
{SceneType::CURRENT, "AdvSceneSwitcher.condition.scene.type.current"},
{SceneType::PREVIOUS, "AdvSceneSwitcher.condition.scene.type.previous"},
};
bool MacroConditionScene::CheckCondition()
{
bool sceneMatch = false;
if (_type == SceneType::CURRENT) {
obs_source_t *rawScene = obs_frontend_get_current_scene();
OBSWeakSource currentScene =
obs_source_get_weak_source(rawScene);
sceneMatch = currentScene == _scene;
obs_weak_source_release(currentScene);
obs_source_release(rawScene);
} else {
sceneMatch = switcher->previousScene == _scene;
}
if (!sceneMatch) {
_duration.Reset();
return false;
}
return _duration.DurationReached();
}
bool MacroConditionScene::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "scene", GetWeakSourceName(_scene).c_str());
obs_data_set_int(obj, "type", static_cast<int>(_type));
_duration.Save(obj);
return true;
}
bool MacroConditionScene::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_scene = GetWeakSourceByName(obs_data_get_string(obj, "scene"));
_type = static_cast<SceneType>(obs_data_get_int(obj, "type"));
_duration.Load(obj);
return true;
}
static inline void populateTypeSelection(QComboBox *list)
{
for (auto entry : sceneTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionSceneEdit::MacroConditionSceneEdit(
QWidget *parent, std::shared_ptr<MacroConditionScene> entryData)
: QWidget(parent)
{
_sceneSelection = new QComboBox();
_sceneType = new QComboBox();
_duration = new DurationSelection();
QWidget::connect(_sceneSelection,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SceneChanged(const QString &)));
QWidget::connect(_sceneType, SIGNAL(currentIndexChanged(int)), this,
SLOT(TypeChanged(int)));
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
AdvSceneSwitcher::populateSceneSelection(_sceneSelection);
populateTypeSelection(_sceneType);
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{scenes}}", _sceneSelection},
{"{{sceneType}}", _sceneType},
{"{{duration}}", _duration},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.scene.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionSceneEdit::SceneChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_scene = GetWeakSourceByQString(text);
}
void MacroConditionSceneEdit::TypeChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_type = static_cast<SceneType>(value);
}
void MacroConditionSceneEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionSceneEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroConditionSceneEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_sceneSelection->setCurrentText(
GetWeakSourceName(_entryData->_scene).c_str());
_sceneType->setCurrentIndex(static_cast<int>(_entryData->_type));
_duration->SetDuration(_entryData->_duration);
}

View File

@@ -0,0 +1,134 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-streaming.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
const int MacroConditionStream::id = 7;
bool MacroConditionStream::_registered = MacroConditionFactory::Register(
MacroConditionStream::id,
{MacroConditionStream::Create, MacroConditionStreamEdit::Create,
"AdvSceneSwitcher.condition.stream"});
static std::map<StreamState, std::string> streamStates = {
{StreamState::STOP, "AdvSceneSwitcher.condition.stream.state.stop"},
{StreamState::START, "AdvSceneSwitcher.condition.stream.state.start"},
};
bool MacroConditionStream::CheckCondition()
{
bool stateMatch = false;
switch (_streamState) {
case StreamState::STOP:
stateMatch = !obs_frontend_streaming_active();
break;
case StreamState::START:
stateMatch = obs_frontend_streaming_active();
break;
default:
break;
}
if (!stateMatch) {
_duration.Reset();
return false;
}
return _duration.DurationReached();
}
bool MacroConditionStream::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_int(obj, "state", static_cast<int>(_streamState));
_duration.Save(obj);
return true;
}
bool MacroConditionStream::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_streamState = static_cast<StreamState>(obs_data_get_int(obj, "state"));
_duration.Load(obj);
return true;
}
static inline void populateStateSelection(QComboBox *list)
{
for (auto entry : streamStates) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionStreamEdit::MacroConditionStreamEdit(
QWidget *parent, std::shared_ptr<MacroConditionStream> entryData)
: QWidget(parent)
{
_streamState = new QComboBox();
_duration = new DurationSelection();
QWidget::connect(_streamState, SIGNAL(currentIndexChanged(int)), this,
SLOT(StateChanged(int)));
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
populateStateSelection(_streamState);
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{streamState}}", _streamState},
{"{{duration}}", _duration},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.stream.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionStreamEdit::StateChanged(int value)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_streamState = static_cast<StreamState>(value);
}
void MacroConditionStreamEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionStreamEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroConditionStreamEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_streamState->setCurrentIndex(
static_cast<int>(_entryData->_streamState));
_duration->SetDuration(_entryData->_duration);
}

View File

@@ -0,0 +1,363 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-video.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include <QFileDialog>
#include <QBuffer>
#include <QToolTip>
#include <QMessageBox>
const int MacroConditionVideo::id = 6;
bool MacroConditionVideo::_registered = MacroConditionFactory::Register(
MacroConditionVideo::id,
{MacroConditionVideo::Create, MacroConditionVideoEdit::Create,
"AdvSceneSwitcher.condition.video"});
static std::map<VideoCondition, std::string> conditionTypes = {
{VideoCondition::MATCH,
"AdvSceneSwitcher.condition.video.condition.match"},
{VideoCondition::DIFFER,
"AdvSceneSwitcher.condition.video.condition.differ"},
{VideoCondition::HAS_NOT_CHANGED,
"AdvSceneSwitcher.condition.video.condition.hasNotChanged"},
{VideoCondition::HAS_CHANGED,
"AdvSceneSwitcher.condition.video.condition.hasChanged"},
{VideoCondition::NO_IMAGE,
"AdvSceneSwitcher.condition.video.condition.noImage"},
};
bool requiresFileInput(VideoCondition t)
{
return t == VideoCondition::MATCH || t == VideoCondition::DIFFER;
}
bool MacroConditionVideo::CheckCondition()
{
bool match = false;
if (_screenshotData) {
if (_screenshotData->done) {
bool imageMatch = Compare();
if (!imageMatch) {
_duration.Reset();
}
if (imageMatch && _duration.DurationReached()) {
match = true;
}
if (!requiresFileInput(_condition)) {
_matchImage = std::move(_screenshotData->image);
}
_screenshotData.reset(nullptr);
}
}
GetScreenshot();
return match;
}
bool MacroConditionVideo::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "videoSource",
GetWeakSourceName(_videoSource).c_str());
obs_data_set_int(obj, "condition", static_cast<int>(_condition));
_duration.Save(obj);
obs_data_set_string(obj, "filePath", _file.c_str());
return true;
}
bool MacroConditionVideo::Load(obs_data_t *obj)
{
const char *videoSourceName = obs_data_get_string(obj, "videoSource");
_videoSource = GetWeakSourceByName(videoSourceName);
_condition =
static_cast<VideoCondition>(obs_data_get_int(obj, "condition"));
_duration.Load(obj);
_file = obs_data_get_string(obj, "filePath");
if (requiresFileInput(_condition)) {
(void)LoadImageFromFile();
}
return true;
}
void MacroConditionVideo::GetScreenshot()
{
auto source = obs_weak_source_get_source(_videoSource);
_screenshotData = std::make_unique<AdvSSScreenshotObj>(source);
obs_source_release(source);
}
bool MacroConditionVideo::LoadImageFromFile()
{
if (!_matchImage.load(QString::fromStdString(_file))) {
blog(LOG_WARNING, "Cannot load image data from file '%s'",
_file.c_str());
return false;
}
_matchImage =
_matchImage.convertToFormat(QImage::Format::Format_RGBX8888);
return true;
}
bool MacroConditionVideo::Compare()
{
switch (_condition) {
case VideoCondition::MATCH:
return _screenshotData->image == _matchImage;
case VideoCondition::DIFFER:
return _screenshotData->image != _matchImage;
case VideoCondition::HAS_CHANGED:
return _screenshotData->image != _matchImage;
case VideoCondition::HAS_NOT_CHANGED:
return _screenshotData->image == _matchImage;
case VideoCondition::NO_IMAGE:
return _screenshotData->image.isNull();
default:
break;
}
return false;
}
static inline void populateConditionSelection(QComboBox *list)
{
for (auto entry : conditionTypes) {
list->addItem(obs_module_text(entry.second.c_str()));
}
}
MacroConditionVideoEdit::MacroConditionVideoEdit(
QWidget *parent, std::shared_ptr<MacroConditionVideo> entryData)
: QWidget(parent)
{
_videoSelection = new QComboBox();
_condition = new QComboBox();
_duration = new DurationSelection();
_filePath = new QLineEdit();
_browseButton =
new QPushButton(obs_module_text("AdvSceneSwitcher.browse"));
_filePath->setFixedWidth(100);
_browseButton->setStyleSheet("border:1px solid gray;");
QWidget::connect(_videoSelection,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SourceChanged(const QString &)));
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this,
SLOT(ConditionChanged(int)));
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
SLOT(DurationUnitChanged(DurationUnit)));
QWidget::connect(_filePath, SIGNAL(editingFinished()), this,
SLOT(FilePathChanged()));
QWidget::connect(_browseButton, SIGNAL(clicked()), this,
SLOT(BrowseButtonClicked()));
AdvSceneSwitcher::populateVideoSelection(_videoSelection, false);
populateConditionSelection(_condition);
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{videoSources}}", _videoSelection},
{"{{condition}}", _condition},
{"{{duration}}", _duration},
{"{{filePath}}", _filePath},
{"{{browseButton}}", _browseButton},
};
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.video.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionVideoEdit::UpdatePreviewTooltip()
{
if (!_entryData) {
return;
}
if (!requiresFileInput(_entryData->_condition)) {
this->setToolTip("");
return;
}
QImage preview = _entryData->GetMatchImage().scaled(
{300, 300}, Qt::KeepAspectRatio);
QByteArray data;
QBuffer buffer(&data);
if (!preview.save(&buffer, "PNG")) {
return;
}
QString html =
QString("<html><img src='data:image/png;base64, %0'/></html>")
.arg(QString(data.toBase64()));
this->setToolTip(html);
}
void MacroConditionVideoEdit::SetFilePath(const QString &text)
{
_filePath->setText(text);
FilePathChanged();
}
void MacroConditionVideoEdit::SourceChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_videoSource = GetWeakSourceByQString(text);
}
void MacroConditionVideoEdit::ConditionChanged(int cond)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_condition = static_cast<VideoCondition>(cond);
if (requiresFileInput(_entryData->_condition)) {
_filePath->show();
_browseButton->show();
} else {
_filePath->hide();
_browseButton->hide();
}
// Reload image data to avoid incorrect matches.
//
// Condition type HAS_NOT_CHANGED will use matchImage to store previous
// frame of video source, which will differ from the image stored at
// specified file location.
if (_entryData->LoadImageFromFile()) {
UpdatePreviewTooltip();
}
}
void MacroConditionVideoEdit::FilePathChanged()
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_file = _filePath->text().toUtf8().constData();
if (_entryData->LoadImageFromFile()) {
UpdatePreviewTooltip();
}
}
void MacroConditionVideoEdit::BrowseButtonClicked()
{
if (_loading || !_entryData) {
return;
}
QString path;
bool useExistingFile = false;
// Ask whether to create screenshot or to select existing file
if (_entryData->_videoSource) {
QMessageBox msgBox(
QMessageBox::Question,
obs_module_text("AdvSceneSwitcher.windowTitle"),
obs_module_text(
"AdvSceneSwitcher.condition.video.askFileAction"),
QMessageBox::Yes | QMessageBox::No);
msgBox.setWindowFlags(Qt::Window | Qt::WindowTitleHint |
Qt::CustomizeWindowHint);
msgBox.setButtonText(
QMessageBox::Yes,
obs_module_text(
"AdvSceneSwitcher.condition.video.askFileAction.file"));
msgBox.setButtonText(
QMessageBox::No,
obs_module_text(
"AdvSceneSwitcher.condition.video.askFileAction.screenshot"));
useExistingFile = msgBox.exec() == QMessageBox::Yes;
}
if (useExistingFile) {
path = QFileDialog::getOpenFileName(this);
if (path.isEmpty()) {
return;
}
} else {
auto source =
obs_weak_source_get_source(_entryData->_videoSource);
auto screenshot = std::make_unique<AdvSSScreenshotObj>(source);
obs_source_release(source);
path = QFileDialog::getSaveFileName(this);
if (path.isEmpty()) {
return;
}
QFile file(path);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
}
if (!screenshot->done) { // Screenshot usually completed by now
std::this_thread::sleep_for(std::chrono::seconds(1));
}
if (!screenshot->done) {
DisplayMessage("Failed to get screenshot of source!");
return;
}
screenshot->image.save(path);
}
SetFilePath(path);
}
void MacroConditionVideoEdit::DurationChanged(double seconds)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.seconds = seconds;
}
void MacroConditionVideoEdit::DurationUnitChanged(DurationUnit unit)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_duration.displayUnit = unit;
}
void MacroConditionVideoEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_videoSelection->setCurrentText(
GetWeakSourceName(_entryData->_videoSource).c_str());
_condition->setCurrentIndex(static_cast<int>(_entryData->_condition));
_duration->SetDuration(_entryData->_duration);
_filePath->setText(QString::fromStdString(_entryData->_file));
if (!requiresFileInput(_entryData->_condition)) {
_filePath->hide();
_browseButton->hide();
}
}

View File

@@ -0,0 +1,195 @@
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-condition-window.hpp"
#include "headers/utility.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include <regex>
const int MacroConditionWindow::id = 1;
bool MacroConditionWindow::_registered = MacroConditionFactory::Register(
MacroConditionWindow::id,
{MacroConditionWindow::Create, MacroConditionWindowEdit::Create,
"AdvSceneSwitcher.condition.window"});
bool MacroConditionWindow::CheckWindowTitleSwitchDirect(
std::string &currentWindowTitle)
{
bool focus = (!_focus || _window == currentWindowTitle);
bool fullscreen = (!_fullscreen || isFullscreen(_window));
bool max = (!_maximized || isMaximized(_window));
return focus && fullscreen && max;
}
bool MacroConditionWindow::CheckWindowTitleSwitchRegex(
std::string &currentWindowTitle, std::vector<std::string> &windowList)
{
bool match = false;
for (auto &window : windowList) {
try {
std::regex expr(_window);
if (!std::regex_match(window, expr)) {
continue;
}
} catch (const std::regex_error &) {
}
bool focus = (!_focus || window == currentWindowTitle);
bool fullscreen = (!_fullscreen || isFullscreen(window));
bool max = (!_maximized || isMaximized(window));
if (focus && fullscreen && max) {
match = true;
break;
}
}
return match;
}
bool MacroConditionWindow::CheckCondition()
{
std::string currentWindowTitle;
GetCurrentWindowTitle(currentWindowTitle);
std::vector<std::string> windowList;
GetWindowList(windowList);
bool match = false;
if (std::find(windowList.begin(), windowList.end(), _window) !=
windowList.end()) {
match = CheckWindowTitleSwitchDirect(currentWindowTitle);
} else {
match = CheckWindowTitleSwitchRegex(currentWindowTitle,
windowList);
}
return match;
}
bool MacroConditionWindow::Save(obs_data_t *obj)
{
MacroCondition::Save(obj);
obs_data_set_string(obj, "window", _window.c_str());
obs_data_set_bool(obj, "fullscreen", _fullscreen);
obs_data_set_bool(obj, "maximized", _maximized);
obs_data_set_bool(obj, "focus", _focus);
return true;
}
bool MacroConditionWindow::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_window = obs_data_get_string(obj, "window");
_fullscreen = obs_data_get_bool(obj, "fullscreen");
#if __APPLE__
// TODO: Implement maximized check on MacOS
_maximized = false;
#else
_maximized = obs_data_get_bool(obj, "maximized");
#endif
_focus = obs_data_get_bool(obj, "focus");
return true;
}
MacroConditionWindowEdit::MacroConditionWindowEdit(
QWidget *parent, std::shared_ptr<MacroConditionWindow> entryData)
: QWidget(parent)
{
_windowSelection = new QComboBox();
_windowSelection->setEditable(true);
_windowSelection->setMaxVisibleItems(20);
_fullscreen = new QCheckBox();
_maximized = new QCheckBox();
_focused = new QCheckBox();
QWidget::connect(_windowSelection,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(WindowChanged(const QString &)));
QWidget::connect(_fullscreen, SIGNAL(stateChanged(int)), this,
SLOT(FullscreenChanged(int)));
QWidget::connect(_maximized, SIGNAL(stateChanged(int)), this,
SLOT(MaximizedChanged(int)));
QWidget::connect(_focused, SIGNAL(stateChanged(int)), this,
SLOT(FocusChanged(int)));
AdvSceneSwitcher::populateWindowSelection(_windowSelection);
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{windows}}", _windowSelection},
{"{{fullscreen}}", _fullscreen},
{"{{maximized}}", _maximized},
{"{{focused}}", _focused},
};
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *line1Layout = new QHBoxLayout;
QHBoxLayout *line2Layout = new QHBoxLayout;
placeWidgets(obs_module_text(
"AdvSceneSwitcher.condition.window.entry.line1"),
line1Layout, widgetPlaceholders);
placeWidgets(obs_module_text(
"AdvSceneSwitcher.condition.window.entry.line2"),
line2Layout, widgetPlaceholders);
mainLayout->addLayout(line1Layout);
mainLayout->addLayout(line2Layout);
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroConditionWindowEdit::WindowChanged(const QString &text)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_window = text.toStdString();
}
void MacroConditionWindowEdit::FullscreenChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_fullscreen = state;
}
void MacroConditionWindowEdit::MaximizedChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_maximized = state;
}
void MacroConditionWindowEdit::FocusChanged(int state)
{
if (_loading || !_entryData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
_entryData->_focus = state;
}
void MacroConditionWindowEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_windowSelection->setCurrentText(_entryData->_window.c_str());
_fullscreen->setChecked(_entryData->_fullscreen);
_maximized->setChecked(_entryData->_maximized);
_focused->setChecked(_entryData->_focus);
}

290
src/macro-tab.cpp Normal file
View File

@@ -0,0 +1,290 @@
#include "headers/macro.hpp"
#include "headers/macro-action-edit.hpp"
#include "headers/macro-condition-edit.hpp"
#include "headers/advanced-scene-switcher.hpp"
#include "headers/name-dialog.hpp"
#include <QMenu>
static QMetaObject::Connection addPulse;
const auto conditionsCollapseThreshold = 4;
const auto actionsCollapseThreshold = 2;
bool macroNameExists(std::string name)
{
for (auto &m : switcher->macros) {
if (m.Name() == name) {
return true;
}
}
return false;
}
bool AdvSceneSwitcher::addNewMacro(std::string &name)
{
QString format{
obs_module_text("AdvSceneSwitcher.macroTab.defaultname")};
int i = 1;
QString placeHolderText = format.arg(i);
while ((macroNameExists(placeHolderText.toUtf8().constData()))) {
placeHolderText = format.arg(++i);
}
bool accepted = AdvSSNameDialog::AskForName(
this, obs_module_text("AdvSceneSwitcher.macroTab.add"),
obs_module_text("AdvSceneSwitcher.macroTab.name"), name,
placeHolderText);
if (!accepted) {
return false;
}
if (name.empty()) {
return false;
}
if (macroNameExists(name)) {
DisplayMessage(
obs_module_text("AdvSceneSwitcher.macroTab.exists"));
return false;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
switcher->macros.emplace_back(name);
}
return true;
}
void AdvSceneSwitcher::on_macroAdd_clicked()
{
std::string name;
if (!addNewMacro(name)) {
return;
}
QString text = QString::fromStdString(name);
QListWidgetItem *item = new QListWidgetItem(text, ui->macros);
item->setData(Qt::UserRole, text);
ui->macros->setCurrentItem(item);
ui->macroAdd->disconnect(addPulse);
ui->macroHelp->setVisible(false);
}
void AdvSceneSwitcher::on_macroRemove_clicked()
{
QListWidgetItem *item = ui->macros->currentItem();
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
int idx = ui->macros->currentRow();
switcher->macros.erase(switcher->macros.begin() + idx);
}
delete item;
if (ui->macros->count() == 0) {
ui->macroHelp->setVisible(true);
}
}
void AdvSceneSwitcher::on_macroUp_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
int index = ui->macros->currentRow();
if (index != -1 && index != 0) {
ui->macros->insertItem(index - 1, ui->macros->takeItem(index));
ui->macros->setCurrentRow(index - 1);
iter_swap(switcher->macros.begin() + index,
switcher->macros.begin() + index - 1);
}
}
void AdvSceneSwitcher::on_macroDown_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
int index = ui->macros->currentRow();
if (index != -1 && index != ui->macros->count() - 1) {
ui->macros->insertItem(index + 1, ui->macros->takeItem(index));
ui->macros->setCurrentRow(index + 1);
iter_swap(switcher->macros.begin() + index,
switcher->macros.begin() + index + 1);
}
}
void AdvSceneSwitcher::on_macroName_editingFinished()
{
bool nameValid = true;
Macro *macro = getSelectedMacro();
if (!macro) {
return;
}
QString newName = ui->macroName->text();
QString oldName = QString::fromStdString(macro->Name());
if (newName.isEmpty() || newName == oldName) {
nameValid = false;
}
if (nameValid && macroNameExists(newName.toUtf8().constData())) {
DisplayMessage(
obs_module_text("AdvSceneSwitcher.macroTab.exists"));
nameValid = false;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
if (nameValid) {
macro->SetName(newName.toUtf8().constData());
QListWidgetItem *item = ui->macros->currentItem();
item->setData(Qt::UserRole, newName);
item->setText(newName);
} else {
ui->macroName->setText(oldName);
}
}
}
void AdvSceneSwitcher::SetEditMacro(Macro &m)
{
ui->macroName->setText(m.Name().c_str());
clearLayout(ui->macroEditConditionLayout);
clearLayout(ui->macroEditActionLayout);
bool collapse = m.Conditions().size() > conditionsCollapseThreshold;
bool root = true;
for (auto &c : m.Conditions()) {
auto newEntry = new MacroConditionEdit(this, &c, c->GetId(),
root, collapse);
ui->macroEditConditionLayout->addWidget(newEntry);
ui->macroEditConditionHelp->setVisible(false);
root = false;
}
collapse = m.Actions().size() > actionsCollapseThreshold;
for (auto &a : m.Actions()) {
auto newEntry =
new MacroActionEdit(this, &a, a->GetId(), collapse);
ui->macroEditActionLayout->addWidget(newEntry);
ui->macroEditActionHelp->setVisible(false);
}
ui->macroEdit->setDisabled(false);
if (m.Conditions().size() == 0) {
ui->macroEditConditionHelp->setVisible(true);
} else {
ui->macroEditConditionHelp->setVisible(false);
}
if (m.Actions().size() == 0) {
ui->macroEditActionHelp->setVisible(true);
} else {
ui->macroEditActionHelp->setVisible(false);
}
}
Macro *AdvSceneSwitcher::getSelectedMacro()
{
Macro *macro = nullptr;
QListWidgetItem *item = ui->macros->currentItem();
if (!item) {
return macro;
}
QString name = item->data(Qt::UserRole).toString();
for (auto &m : switcher->macros) {
if (name.compare(m.Name().c_str()) == 0) {
macro = &m;
break;
}
}
return macro;
}
void AdvSceneSwitcher::on_macros_currentRowChanged(int idx)
{
if (loading) {
return;
}
if (idx == -1) {
ui->macroEdit->setDisabled(true);
return;
}
QListWidgetItem *item = ui->macros->item(idx);
QString macroName = item->data(Qt::UserRole).toString();
for (auto &m : switcher->macros) {
if (macroName.compare(m.Name().c_str()) == 0) {
SetEditMacro(m);
break;
}
}
}
void AdvSceneSwitcher::setupMacroTab()
{
for (auto &m : switcher->macros) {
QString text = QString::fromStdString(m.Name());
QListWidgetItem *item = new QListWidgetItem(text, ui->macros);
item->setData(Qt::UserRole, text);
}
if (switcher->macros.size() == 0) {
addPulse = PulseWidget(ui->macroAdd, QColor(Qt::green));
ui->macroHelp->setVisible(true);
} else {
ui->macroHelp->setVisible(false);
}
ui->macros->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->macros, SIGNAL(customContextMenuRequested(QPoint)), this,
SLOT(showMacroContextMenu(QPoint)));
ui->macroEdit->setDisabled(true);
}
void AdvSceneSwitcher::showMacroContextMenu(const QPoint &pos)
{
QPoint globalPos = ui->macros->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.copy"),
this, SLOT(copyMacro()));
myMenu.exec(globalPos);
}
void AdvSceneSwitcher::copyMacro()
{
obs_data_t *data = obs_data_create();
getSelectedMacro()->Save(data);
std::string name;
if (!addNewMacro(name)) {
obs_data_release(data);
return;
}
switcher->macros.back().Load(data);
switcher->macros.back().SetName(name);
obs_data_release(data);
QString text = QString::fromStdString(name);
QListWidgetItem *item = new QListWidgetItem(text, ui->macros);
item->setData(Qt::UserRole, text);
ui->macros->setCurrentItem(item);
}

298
src/macro.cpp Normal file
View File

@@ -0,0 +1,298 @@
#include "headers/macro.hpp"
#include "headers/macro-action-edit.hpp"
#include "headers/macro-condition-edit.hpp"
#include "headers/macro-action-switch-scene.hpp"
const std::map<LogicType, LogicTypeInfo> MacroCondition::logicTypes = {
{LogicType::NONE, {"AdvSceneSwitcher.logic.none"}},
{LogicType::AND, {"AdvSceneSwitcher.logic.and"}},
{LogicType::OR, {"AdvSceneSwitcher.logic.or"}},
{LogicType::AND_NOT, {"AdvSceneSwitcher.logic.andNot"}},
{LogicType::OR_NOT, {"AdvSceneSwitcher.logic.orNot"}},
{LogicType::ROOT_NONE, {"AdvSceneSwitcher.logic.rootNone"}},
{LogicType::ROOT_NOT, {"AdvSceneSwitcher.logic.not"}},
};
Macro::Macro(std::string name) : _name(name) {}
Macro::~Macro() {}
bool Macro::CeckMatch()
{
_matched = false;
for (auto &c : _conditions) {
bool cond = c->CheckCondition();
switch (c->GetLogicType()) {
case LogicType::NONE:
vblog(LOG_INFO,
"ignoring condition check 'none' for '%s'",
_name.c_str());
continue;
break;
case LogicType::AND:
_matched = _matched && cond;
break;
case LogicType::OR:
_matched = _matched || cond;
break;
case LogicType::AND_NOT:
_matched = _matched && !cond;
break;
case LogicType::OR_NOT:
_matched = _matched || !cond;
break;
case LogicType::ROOT_NONE:
_matched = cond;
break;
case LogicType::ROOT_NOT:
_matched = !cond;
break;
default:
blog(LOG_WARNING,
"ignoring unkown condition check for '%s'",
_name.c_str());
break;
}
}
return _matched;
}
bool Macro::PerformAction()
{
bool ret = true;
for (auto &a : _actions) {
ret = ret && a->PerformAction();
a->LogAction();
if (!ret) {
return false;
}
}
return ret;
}
bool Macro::Save(obs_data_t *obj)
{
obs_data_set_string(obj, "name", _name.c_str());
obs_data_array_t *conditions = obs_data_array_create();
for (auto &c : _conditions) {
obs_data_t *array_obj = obs_data_create();
c->Save(array_obj);
obs_data_array_push_back(conditions, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "conditions", conditions);
obs_data_array_release(conditions);
obs_data_array_t *actions = obs_data_array_create();
for (auto &a : _actions) {
obs_data_t *array_obj = obs_data_create();
a->Save(array_obj);
obs_data_array_push_back(actions, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "actions", actions);
obs_data_array_release(actions);
return true;
}
bool isValidLogic(LogicType t, bool root)
{
bool isRoot = isRootLogicType(t);
if (!isRoot == root) {
return false;
}
if (isRoot) {
if (t >= LogicType::ROOT_LAST) {
return false;
}
} else if (t >= LogicType::LAST) {
return false;
}
return true;
}
void setValidLogic(MacroCondition *c, bool root, std::string name)
{
if (isValidLogic(c->GetLogicType(), root)) {
return;
}
if (root) {
c->SetLogicType(LogicType::ROOT_NONE);
blog(LOG_WARNING,
"setting invalid logic selection to 'if' for macro %s",
name.c_str());
} else {
c->SetLogicType(LogicType::NONE);
blog(LOG_WARNING,
"setting invalid logic selection to 'ignore' for macro %s",
name.c_str());
}
}
bool Macro::Load(obs_data_t *obj)
{
_name = obs_data_get_string(obj, "name");
bool root = true;
obs_data_array_t *conditions = obs_data_get_array(obj, "conditions");
size_t count = obs_data_array_count(conditions);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(conditions, i);
int id = obs_data_get_int(array_obj, "id");
auto newEntry = MacroConditionFactory::Create(id);
if (newEntry) {
_conditions.emplace_back(newEntry);
auto c = _conditions.back().get();
c->Load(array_obj);
setValidLogic(c, root, _name);
} else {
blog(LOG_WARNING,
"discarding condition entry with unkown id (%d) for macro %s",
id, _name.c_str());
}
obs_data_release(array_obj);
root = false;
}
obs_data_array_release(conditions);
obs_data_array_t *actions = obs_data_get_array(obj, "actions");
count = obs_data_array_count(actions);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(actions, i);
int id = obs_data_get_int(array_obj, "id");
auto newEntry = MacroActionFactory::Create(id);
if (newEntry) {
_actions.emplace_back(newEntry);
_actions.back()->Load(array_obj);
} else {
blog(LOG_WARNING,
"discarding action entry with unkown id (%d) for macro %s",
id, _name.c_str());
}
obs_data_release(array_obj);
}
obs_data_array_release(actions);
return true;
}
bool Macro::SwitchesScene()
{
MacroActionSwitchScene temp;
for (auto &a : _actions) {
if (a->GetId() == temp.GetId()) {
return true;
}
}
return false;
}
bool MacroCondition::Save(obs_data_t *obj)
{
obs_data_set_int(obj, "id", GetId());
obs_data_set_int(obj, "logic", static_cast<int>(_logic));
return true;
}
bool MacroCondition::Load(obs_data_t *obj)
{
_logic = static_cast<LogicType>(obs_data_get_int(obj, "logic"));
return true;
}
bool MacroAction::Save(obs_data_t *obj)
{
obs_data_set_int(obj, "id", GetId());
return true;
}
bool MacroAction::Load(obs_data_t *obj)
{
UNUSED_PARAMETER(obj);
return true;
}
void MacroAction::LogAction()
{
blog(LOG_INFO, "performed action %d", GetId());
}
void SwitcherData::saveMacros(obs_data_t *obj)
{
obs_data_array_t *macroArray = obs_data_array_create();
for (auto &m : macros) {
obs_data_t *array_obj = obs_data_create();
m.Save(array_obj);
obs_data_array_push_back(macroArray, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "macros", macroArray);
obs_data_array_release(macroArray);
}
void SwitcherData::loadMacros(obs_data_t *obj)
{
macros.clear();
obs_data_array_t *macroArray = obs_data_get_array(obj, "macros");
size_t count = obs_data_array_count(macroArray);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(macroArray, i);
macros.emplace_back();
macros.back().Load(array_obj);
obs_data_release(array_obj);
}
obs_data_array_release(macroArray);
}
bool SwitcherData::checkMacros()
{
bool ret = false;
for (auto &m : macros) {
if (m.CeckMatch()) {
ret = true;
// This has to be performed here for now as actions are
// not performed immediately after checking conditions.
if (m.SwitchesScene()) {
switcher->macroSceneSwitched = true;
}
}
}
return ret;
}
bool SwitcherData::runMacros()
{
for (auto &m : macros) {
if (m.Matched()) {
blog(LOG_INFO, "running macro: %s", m.Name().c_str());
if (!m.PerformAction()) {
blog(LOG_WARNING, "abort macro: %s",
m.Name().c_str());
return false;
}
}
}
return true;
}

66
src/name-dialog.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include "headers/name-dialog.hpp"
AdvSSNameDialog::AdvSSNameDialog(QWidget *parent) : QDialog(parent)
{
setModal(true);
setWindowModality(Qt::WindowModality::WindowModal);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setFixedWidth(555);
setMinimumHeight(100);
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
label = new QLabel(this);
layout->addWidget(label);
label->setText("Set Text");
userText = new QLineEdit(this);
layout->addWidget(userText);
QDialogButtonBox *buttonbox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(buttonbox);
buttonbox->setCenterButtons(true);
connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
static bool IsWhitespace(char ch)
{
return ch == ' ' || ch == '\t';
}
static void CleanWhitespace(std::string &str)
{
while (str.size() && IsWhitespace(str.back()))
str.erase(str.end() - 1);
while (str.size() && IsWhitespace(str.front()))
str.erase(str.begin());
}
bool AdvSSNameDialog::AskForName(QWidget *parent, const QString &title,
const QString &text,
std::string &userTextInput,
const QString &placeHolder, int maxSize)
{
if (maxSize <= 0 || maxSize > 32767) {
maxSize = 170;
}
AdvSSNameDialog dialog(parent);
dialog.setWindowTitle(title);
dialog.label->setText(text);
dialog.userText->setMaxLength(maxSize);
dialog.userText->setText(placeHolder);
dialog.userText->selectAll();
if (dialog.exec() != DialogCode::Accepted) {
return false;
}
userTextInput = dialog.userText->text().toUtf8().constData();
CleanWhitespace(userTextInput);
return true;
}

View File

@@ -4,7 +4,9 @@
#import <Carbon/Carbon.h>
#include <Carbon/Carbon.h>
#include <util/platform.h>
#include "../headers/advanced-scene-switcher.hpp"
#include <vector>
#include <QStringList>
#include <QRegularExpression>
void GetWindowList(std::vector<std::string> &windows)
{

683
src/scene-group.cpp Normal file
View File

@@ -0,0 +1,683 @@
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <random>
#include "headers/advanced-scene-switcher.hpp"
#include "headers/name-dialog.hpp"
#include "headers/utility.hpp"
static QMetaObject::Connection addPulse;
SceneGroupEditWidget *typeEdit = nullptr;
void SceneGroup::advanceIdx()
{
currentIdx++;
if (currentIdx >= scenes.size()) {
if (repeat) {
currentIdx = 0;
} else {
currentIdx = scenes.size() - 1;
}
}
}
OBSWeakSource SceneGroup::getNextSceneCount()
{
currentCount++;
if (currentCount >= count) {
advanceIdx();
currentCount = 0;
}
return scenes[currentIdx];
}
OBSWeakSource SceneGroup::getNextSceneTime()
{
if (lastAdvTime.time_since_epoch().count() == 0) {
lastAdvTime = std::chrono::high_resolution_clock::now();
}
auto now = std::chrono::high_resolution_clock::now();
auto passedTime = std::chrono::duration_cast<std::chrono::milliseconds>(
now - lastAdvTime);
if (passedTime.count() >= time * 1000) {
advanceIdx();
lastAdvTime = now;
}
return scenes[currentIdx];
}
OBSWeakSource SceneGroup::getNextSceneRandom()
{
if (scenes.size() == 1) {
currentIdx = 0;
return scenes[currentIdx];
}
int rIdx = lastRandomScene;
do {
rIdx = rand() % scenes.size();
} while (rIdx == lastRandomScene);
lastRandomScene = rIdx;
currentIdx = rIdx;
return scenes[currentIdx];
}
OBSWeakSource SceneGroup::getCurrentScene()
{
if (scenes.size() < currentIdx + 1) {
return nullptr;
}
return scenes[currentIdx];
}
OBSWeakSource SceneGroup::getNextScene()
{
if (scenes.empty()) {
return nullptr;
}
switch (type) {
case AdvanceCondition::Count:
return getNextSceneCount();
break;
case AdvanceCondition::Time:
return getNextSceneTime();
break;
case AdvanceCondition::Random:
return getNextSceneRandom();
break;
}
blog(LOG_INFO, "unknown scene group type!");
return nullptr;
}
bool sceneGroupNameExists(std::string name)
{
obs_source_t *source = obs_get_source_by_name(name.c_str());
if (source) {
obs_source_release(source);
return true;
}
for (SceneGroup &sg : switcher->sceneGroups) {
if (sg.name == name) {
return true;
}
}
return (name == obs_module_text(
"AdvSceneSwitcher.selectPreviousScene") ||
(name == invalid_scene_group_name));
}
void AdvSceneSwitcher::on_sceneGroupAdd_clicked()
{
std::string name;
QString format{
obs_module_text("AdvSceneSwitcher.sceneGroupTab.defaultname")};
int i = 1;
QString placeHolderText = format.arg(i);
while ((sceneGroupNameExists(placeHolderText.toUtf8().constData()))) {
placeHolderText = format.arg(++i);
}
bool accepted = AdvSSNameDialog::AskForName(
this, obs_module_text("AdvSceneSwitcher.sceneGroupTab.add"),
obs_module_text("AdvSceneSwitcher.sceneGroupTab.add"), name,
placeHolderText);
if (!accepted) {
return;
}
if (name.empty()) {
return;
}
if (sceneGroupNameExists(name)) {
DisplayMessage(obs_module_text(
"AdvSceneSwitcher.sceneGroupTab.exists"));
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
switcher->sceneGroups.emplace_back(name);
}
QString text = QString::fromStdString(name);
QListWidgetItem *item = new QListWidgetItem(text, ui->sceneGroups);
item->setData(Qt::UserRole, text);
ui->sceneGroups->setCurrentItem(item);
ui->sceneGroupAdd->disconnect(addPulse);
ui->sceneGroupHelp->setVisible(false);
emit SceneGroupAdded(QString::fromStdString(name));
}
void AdvSceneSwitcher::on_sceneGroupRemove_clicked()
{
QListWidgetItem *item = ui->sceneGroups->currentItem();
if (!item) {
return;
}
QString name;
{
std::lock_guard<std::mutex> lock(switcher->m);
int idx = ui->sceneGroups->currentRow();
auto &sg = switcher->sceneGroups;
name = QString::fromStdString(sg[idx].name);
sg.erase(sg.begin() + idx);
}
delete item;
emit SceneGroupRemoved(name);
}
void AdvSceneSwitcher::on_sceneGroupUp_clicked()
{
int index = ui->sceneGroups->currentRow();
if (index != -1 && index != 0) {
ui->sceneGroups->insertItem(index - 1,
ui->sceneGroups->takeItem(index));
ui->sceneGroups->setCurrentRow(index - 1);
std::lock_guard<std::mutex> lock(switcher->m);
iter_swap(switcher->sceneGroups.begin() + index,
switcher->sceneGroups.begin() + index - 1);
}
}
void AdvSceneSwitcher::on_sceneGroupDown_clicked()
{
int index = ui->sceneGroups->currentRow();
if (index != -1 && index != ui->sceneGroups->count() - 1) {
ui->sceneGroups->insertItem(index + 1,
ui->sceneGroups->takeItem(index));
ui->sceneGroups->setCurrentRow(index + 1);
std::lock_guard<std::mutex> lock(switcher->m);
iter_swap(switcher->sceneGroups.begin() + index,
switcher->sceneGroups.begin() + index + 1);
}
}
SceneGroup *getSelectedSG(Ui_AdvSceneSwitcher *ui)
{
SceneGroup *currentSG = nullptr;
QListWidgetItem *sgItem = ui->sceneGroups->currentItem();
if (!sgItem) {
return currentSG;
}
QString sgName = sgItem->data(Qt::UserRole).toString();
for (auto &sg : switcher->sceneGroups) {
if (sgName.compare(sg.name.c_str()) == 0) {
currentSG = &sg;
break;
}
}
return currentSG;
}
void AdvSceneSwitcher::on_sceneGroupName_editingFinished()
{
bool nameValid = true;
SceneGroup *currentSG = getSelectedSG(ui.get());
if (!currentSG) {
return;
}
QString newName = ui->sceneGroupName->text();
QString oldName = QString::fromStdString(currentSG->name);
if (newName.isEmpty() || newName == oldName) {
nameValid = false;
}
if (nameValid && sceneGroupNameExists(newName.toUtf8().constData())) {
DisplayMessage(obs_module_text(
"AdvSceneSwitcher.sceneGroupTab.exists"));
nameValid = false;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
if (nameValid) {
currentSG->name = newName.toUtf8().constData();
QListWidgetItem *sgItem =
ui->sceneGroups->currentItem();
sgItem->setData(Qt::UserRole, newName);
sgItem->setText(newName);
} else {
ui->sceneGroupName->setText(oldName);
}
}
emit SceneGroupRenamed(oldName, newName);
}
void AdvSceneSwitcher::SetEditSceneGroup(SceneGroup &sg)
{
ui->sceneGroupName->setText(sg.name.c_str());
ui->sceneGroupScenes->clear();
for (auto &s : sg.scenes) {
QString sceneName =
QString::fromStdString(GetWeakSourceName(s));
QVariant v = QVariant::fromValue(sceneName);
QListWidgetItem *item =
new QListWidgetItem(sceneName, ui->sceneGroupScenes);
item->setData(Qt::UserRole, v);
}
ui->sceneGroupEdit->setDisabled(false);
typeEdit->SetEditSceneGroup(&sg);
if (sg.scenes.size() == 0) {
ui->sceneGroupScenesHelp->setVisible(true);
} else {
ui->sceneGroupScenesHelp->setVisible(false);
}
}
void AdvSceneSwitcher::on_sceneGroups_currentRowChanged(int idx)
{
if (loading) {
return;
}
if (idx == -1) {
ui->sceneGroupEdit->setDisabled(true);
return;
}
QListWidgetItem *item = ui->sceneGroups->item(idx);
QString sgName = item->data(Qt::UserRole).toString();
for (auto &sg : switcher->sceneGroups) {
if (sgName.compare(sg.name.c_str()) == 0) {
SetEditSceneGroup(sg);
break;
}
}
}
void AdvSceneSwitcher::on_sceneGroupSceneAdd_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
SceneGroup *currentSG = getSelectedSG(ui.get());
if (!currentSG) {
return;
}
QString sceneName = ui->sceneGroupSceneSelection->currentText();
if (sceneName.isEmpty()) {
return;
}
OBSWeakSource source = GetWeakSourceByQString(sceneName);
if (!source) {
return;
}
QVariant v = QVariant::fromValue(sceneName);
QListWidgetItem *item =
new QListWidgetItem(sceneName, ui->sceneGroupScenes);
item->setData(Qt::UserRole, v);
currentSG->scenes.emplace_back(source);
ui->sceneGroupScenesHelp->setVisible(false);
}
void AdvSceneSwitcher::on_sceneGroupSceneRemove_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
SceneGroup *currentSG = getSelectedSG(ui.get());
if (!currentSG) {
return;
}
int idx = ui->sceneGroupScenes->currentRow();
if (idx == -1) {
return;
}
auto &scenes = currentSG->scenes;
scenes.erase(scenes.begin() + idx);
auto item = ui->sceneGroupScenes->currentItem();
delete item;
}
void AdvSceneSwitcher::on_sceneGroupSceneUp_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
SceneGroup *currentSG = getSelectedSG(ui.get());
if (!currentSG) {
return;
}
int index = ui->sceneGroupScenes->currentRow();
if (index != -1 && index != 0) {
ui->sceneGroupScenes->insertItem(
index - 1, ui->sceneGroupScenes->takeItem(index));
ui->sceneGroupScenes->setCurrentRow(index - 1);
iter_swap(currentSG->scenes.begin() + index,
currentSG->scenes.begin() + index - 1);
}
}
void AdvSceneSwitcher::on_sceneGroupSceneDown_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
SceneGroup *currentSG = getSelectedSG(ui.get());
if (!currentSG) {
return;
}
int index = ui->sceneGroupScenes->currentRow();
if (index != -1 && index != ui->sceneGroupScenes->count() - 1) {
ui->sceneGroupScenes->insertItem(
index + 1, ui->sceneGroupScenes->takeItem(index));
ui->sceneGroupScenes->setCurrentRow(index + 1);
iter_swap(currentSG->scenes.begin() + index,
currentSG->scenes.begin() + index + 1);
}
}
void SwitcherData::saveSceneGroups(obs_data_t *obj)
{
obs_data_array_t *sceneGroupArray = obs_data_array_create();
for (SceneGroup &sg : sceneGroups) {
obs_data_t *array_obj = obs_data_create();
obs_data_set_string(array_obj, "name", sg.name.c_str());
obs_data_set_int(array_obj, "type", static_cast<int>(sg.type));
obs_data_array_t *scenesArray = obs_data_array_create();
for (OBSWeakSource s : sg.scenes) {
obs_data_t *sceneArray_obj = obs_data_create();
obs_source_t *source = obs_weak_source_get_source(s);
if (source) {
const char *name = obs_source_get_name(source);
obs_data_set_string(sceneArray_obj, "scene",
name);
}
obs_source_release(source);
obs_data_array_push_back(scenesArray, sceneArray_obj);
obs_data_release(sceneArray_obj);
}
obs_data_set_array(array_obj, "scenes", scenesArray);
obs_data_array_release(scenesArray);
obs_data_set_int(array_obj, "count", sg.count);
obs_data_set_double(array_obj, "time", sg.time);
obs_data_set_bool(array_obj, "repeat", sg.repeat);
obs_data_array_push_back(sceneGroupArray, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "sceneGroups", sceneGroupArray);
obs_data_array_release(sceneGroupArray);
}
void SwitcherData::loadSceneGroups(obs_data_t *obj)
{
sceneGroups.clear();
obs_data_array_t *sceneGroupArray =
obs_data_get_array(obj, "sceneGroups");
size_t count = obs_data_array_count(sceneGroupArray);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(sceneGroupArray, i);
const char *name = obs_data_get_string(array_obj, "name");
AdvanceCondition type = static_cast<AdvanceCondition>(
obs_data_get_int(array_obj, "type"));
std::vector<OBSWeakSource> scenes;
obs_data_array_t *scenesArray =
obs_data_get_array(array_obj, "scenes");
size_t scenesCount = obs_data_array_count(scenesArray);
for (size_t j = 0; j < scenesCount; j++) {
obs_data_t *scenesArray_obj =
obs_data_array_item(scenesArray, j);
const char *scene =
obs_data_get_string(scenesArray_obj, "scene");
scenes.emplace_back(GetWeakSourceByName(scene));
obs_data_release(scenesArray_obj);
}
obs_data_array_release(scenesArray);
int count = obs_data_get_int(array_obj, "count");
double time = obs_data_get_double(array_obj, "time");
bool repeat = obs_data_get_bool(array_obj, "repeat");
sceneGroups.emplace_back(name, type, scenes, count, time,
repeat);
obs_data_release(array_obj);
}
obs_data_array_release(sceneGroupArray);
}
void AdvSceneSwitcher::setupSceneGroupTab()
{
populateSceneSelection(ui->sceneGroupSceneSelection);
for (auto &sg : switcher->sceneGroups) {
QString text = QString::fromStdString(sg.name);
QListWidgetItem *item =
new QListWidgetItem(text, ui->sceneGroups);
item->setData(Qt::UserRole, text);
}
if (switcher->sceneGroups.size() == 0) {
addPulse = PulseWidget(ui->sceneGroupAdd, QColor(Qt::green));
ui->sceneGroupHelp->setVisible(true);
} else {
ui->sceneGroupHelp->setVisible(false);
}
typeEdit = new SceneGroupEditWidget();
ui->sceneGroupTypeEdit->addWidget(typeEdit);
ui->sceneGroupEdit->setDisabled(true);
}
void populateTypeSelection(QComboBox *list)
{
list->addItem(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.type.count"));
list->addItem(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.type.time"));
list->addItem(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.type.random"));
}
SceneGroupEditWidget::SceneGroupEditWidget()
{
type = new QComboBox();
populateTypeSelection(type);
QWidget::connect(type, SIGNAL(currentIndexChanged(int)), this,
SLOT(TypeChanged(int)));
QHBoxLayout *typeLayout = new QHBoxLayout();
typeLayout->setContentsMargins(0, 0, 0, 0);
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{type}}", type}};
placeWidgets(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.edit.type"),
typeLayout, widgetPlaceholders);
countEdit = new QWidget();
count = new QSpinBox();
count->setMinimum(1);
count->setMaximum(999);
QWidget::connect(count, SIGNAL(valueChanged(int)), this,
SLOT(CountChanged(int)));
QHBoxLayout *countLayout = new QHBoxLayout(countEdit);
countLayout->setContentsMargins(0, 0, 0, 0);
widgetPlaceholders = {{"{{count}}", count}};
placeWidgets(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.edit.count"),
countLayout, widgetPlaceholders);
timeEdit = new QWidget();
time = new QDoubleSpinBox();
time->setMinimum(0.0);
time->setMaximum(99999999.00);
time->setSuffix("s");
QWidget::connect(time, SIGNAL(valueChanged(double)), this,
SLOT(TimeChanged(double)));
QHBoxLayout *timeLayout = new QHBoxLayout(timeEdit);
timeLayout->setContentsMargins(0, 0, 0, 0);
widgetPlaceholders = {{"{{time}}", time}};
placeWidgets(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.edit.time"),
timeLayout, widgetPlaceholders);
repeat = new QCheckBox(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.edit.repeat"));
QWidget::connect(repeat, SIGNAL(stateChanged(int)), this,
SLOT(RepeatChanged(int)));
random = new QLabel(
obs_module_text("AdvSceneSwitcher.sceneGroupTab.edit.random"));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addLayout(typeLayout);
mainLayout->addWidget(countEdit);
mainLayout->addWidget(timeEdit);
mainLayout->addWidget(repeat);
mainLayout->addWidget(random);
setLayout(mainLayout);
countEdit->setVisible(false);
timeEdit->setVisible(false);
repeat->setVisible(false);
random->setVisible(false);
sceneGroup = nullptr;
}
void SceneGroupEditWidget::ShowCurrentTypeEdit()
{
if (!sceneGroup) {
return;
}
countEdit->setVisible(false);
timeEdit->setVisible(false);
repeat->setVisible(false);
random->setVisible(false);
switch (sceneGroup->type) {
case AdvanceCondition::Count:
countEdit->setVisible(true);
repeat->setVisible(true);
break;
case AdvanceCondition::Time:
timeEdit->setVisible(true);
repeat->setVisible(true);
break;
case AdvanceCondition::Random:
random->setVisible(true);
break;
}
}
void SceneGroupEditWidget::SetEditSceneGroup(SceneGroup *sg)
{
if (!sg) {
return;
}
sceneGroup = sg;
type->setCurrentIndex(static_cast<int>(sg->type));
count->setValue(sg->count);
time->setValue(sg->time);
repeat->setChecked(sg->repeat);
ShowCurrentTypeEdit();
}
void SceneGroupEditWidget::TypeChanged(int type)
{
if (!sceneGroup) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
sceneGroup->type = static_cast<AdvanceCondition>(type);
ShowCurrentTypeEdit();
}
void SceneGroupEditWidget::CountChanged(int count)
{
if (!sceneGroup) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
sceneGroup->count = count;
}
void SceneGroupEditWidget::TimeChanged(double time)
{
if (!sceneGroup) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
sceneGroup->time = time;
}
void SceneGroupEditWidget::RepeatChanged(int state)
{
if (!sceneGroup) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
sceneGroup->repeat = state;
}

554
src/scene-trigger.cpp Normal file
View File

@@ -0,0 +1,554 @@
#include <thread>
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
bool SceneTrigger::pause = false;
static QMetaObject::Connection addPulse;
void AdvSceneSwitcher::on_triggerAdd_clicked()
{
std::lock_guard<std::mutex> lock(switcher->m);
switcher->sceneTriggers.emplace_back();
listAddClicked(ui->sceneTriggers,
new SceneTriggerWidget(this,
&switcher->sceneTriggers.back()),
ui->triggerAdd, &addPulse);
ui->triggerHelp->setVisible(false);
}
void AdvSceneSwitcher::on_triggerRemove_clicked()
{
QListWidgetItem *item = ui->sceneTriggers->currentItem();
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
int idx = ui->sceneTriggers->currentRow();
auto &switches = switcher->sceneTriggers;
switches.erase(switches.begin() + idx);
}
delete item;
}
void AdvSceneSwitcher::on_triggerUp_clicked()
{
int index = ui->sceneTriggers->currentRow();
if (!listMoveUp(ui->sceneTriggers)) {
return;
}
SceneTriggerWidget *s1 =
(SceneTriggerWidget *)ui->sceneTriggers->itemWidget(
ui->sceneTriggers->item(index));
SceneTriggerWidget *s2 =
(SceneTriggerWidget *)ui->sceneTriggers->itemWidget(
ui->sceneTriggers->item(index - 1));
SceneTriggerWidget::swapSwitchData(s1, s2);
std::lock_guard<std::mutex> lock(switcher->m);
std::swap(switcher->sceneTriggers[index],
switcher->sceneTriggers[index - 1]);
}
void AdvSceneSwitcher::on_triggerDown_clicked()
{
int index = ui->sceneTriggers->currentRow();
if (!listMoveDown(ui->sceneTriggers)) {
return;
}
SceneTriggerWidget *s1 =
(SceneTriggerWidget *)ui->sceneTriggers->itemWidget(
ui->sceneTriggers->item(index));
SceneTriggerWidget *s2 =
(SceneTriggerWidget *)ui->sceneTriggers->itemWidget(
ui->sceneTriggers->item(index + 1));
SceneTriggerWidget::swapSwitchData(s1, s2);
std::lock_guard<std::mutex> lock(switcher->m);
std::swap(switcher->sceneTriggers[index],
switcher->sceneTriggers[index + 1]);
}
void SceneTrigger::logMatch()
{
std::string sceneName = "";
std::string statusName = "";
std::string actionName = "";
switch (triggerType) {
case sceneTriggerType::NONE:
statusName = "NONE";
break;
case sceneTriggerType::SCENE_ACTIVE:
statusName = "SCENE ACTIVE";
break;
case sceneTriggerType::SCENE_INACTIVE:
statusName = "SCENE INACTIVE";
break;
case sceneTriggerType::SCENE_LEAVE:
statusName = "SCENE LEAVE";
break;
default:
break;
}
switch (triggerAction) {
case sceneTriggerAction::NONE:
actionName = "NONE";
break;
case sceneTriggerAction::START_RECORDING:
actionName = "START RECORDING";
break;
case sceneTriggerAction::PAUSE_RECORDING:
actionName = "PAUSE RECORDING";
break;
case sceneTriggerAction::UNPAUSE_RECORDING:
actionName = "UNPAUSE RECORDING";
break;
case sceneTriggerAction::STOP_RECORDING:
actionName = "STOP RECORDING";
break;
case sceneTriggerAction::START_STREAMING:
actionName = "START STREAMING";
break;
case sceneTriggerAction::STOP_STREAMING:
actionName = "STOP STREAMING";
break;
case sceneTriggerAction::START_REPLAY_BUFFER:
actionName = "START REPLAY BUFFER";
break;
case sceneTriggerAction::STOP_REPLAY_BUFFER:
actionName = "STOP REPLAY BUFFER";
break;
case sceneTriggerAction::MUTE_SOURCE:
actionName = "MUTE (" + GetWeakSourceName(audioSource) + ")";
break;
case sceneTriggerAction::UNMUTE_SOURCE:
actionName = "UNMUTE (" + GetWeakSourceName(audioSource) + ")";
break;
case sceneTriggerAction::START_SWITCHER:
actionName = "START SCENE SWITCHER";
break;
case sceneTriggerAction::STOP_SWITCHER:
actionName = "STOP SCENE SWITCHER";
break;
default:
actionName = "UNKOWN";
break;
}
blog(LOG_INFO,
"scene '%s' in status '%s' triggering action '%s' after %f seconds",
GetWeakSourceName(scene).c_str(), statusName.c_str(),
actionName.c_str(), duration);
}
void frontEndActionThread(sceneTriggerAction action, double delay)
{
long long mil = delay * 1000;
std::this_thread::sleep_for(std::chrono::milliseconds(mil));
switch (action) {
case sceneTriggerAction::NONE:
break;
case sceneTriggerAction::START_RECORDING:
obs_frontend_recording_start();
break;
case sceneTriggerAction::PAUSE_RECORDING:
obs_frontend_recording_pause(true);
break;
case sceneTriggerAction::UNPAUSE_RECORDING:
obs_frontend_recording_pause(false);
break;
case sceneTriggerAction::STOP_RECORDING:
obs_frontend_recording_stop();
break;
case sceneTriggerAction::START_STREAMING:
obs_frontend_streaming_start();
break;
case sceneTriggerAction::STOP_STREAMING:
obs_frontend_streaming_stop();
break;
case sceneTriggerAction::START_REPLAY_BUFFER:
obs_frontend_replay_buffer_start();
break;
case sceneTriggerAction::STOP_REPLAY_BUFFER:
obs_frontend_replay_buffer_stop();
break;
default:
blog(LOG_WARNING, "ignoring unexpected frontend action '%d'",
static_cast<int>(action));
break;
}
}
void muteThread(OBSWeakSource source, double delay, bool mute)
{
long long mil = delay * 1000;
std::this_thread::sleep_for(std::chrono::milliseconds(mil));
auto s = obs_weak_source_get_source(source);
obs_source_set_muted(s, mute);
obs_source_release(s);
}
void statusThread(double delay, bool stop)
{
long long mil = delay * 1000;
std::this_thread::sleep_for(std::chrono::milliseconds(mil));
if (stop) {
switcher->Stop();
} else {
switcher->Start();
}
}
bool isFrontendAction(sceneTriggerAction triggerAction)
{
return triggerAction == sceneTriggerAction::START_RECORDING ||
triggerAction == sceneTriggerAction::PAUSE_RECORDING ||
triggerAction == sceneTriggerAction::UNPAUSE_RECORDING ||
triggerAction == sceneTriggerAction::STOP_RECORDING ||
triggerAction == sceneTriggerAction::START_STREAMING ||
triggerAction == sceneTriggerAction::STOP_STREAMING ||
triggerAction == sceneTriggerAction::START_REPLAY_BUFFER ||
triggerAction == sceneTriggerAction::STOP_REPLAY_BUFFER;
}
bool isAudioAction(sceneTriggerAction t)
{
return t == sceneTriggerAction::MUTE_SOURCE ||
t == sceneTriggerAction::UNMUTE_SOURCE;
}
bool isSwitcherStatusAction(sceneTriggerAction t)
{
return t == sceneTriggerAction::START_SWITCHER ||
t == sceneTriggerAction::STOP_SWITCHER;
}
void SceneTrigger::performAction()
{
if (triggerAction == sceneTriggerAction::NONE) {
return;
}
std::thread t;
if (isFrontendAction(triggerAction)) {
t = std::thread(frontEndActionThread, triggerAction, duration);
} else if (isAudioAction(triggerAction)) {
bool mute = triggerAction == sceneTriggerAction::MUTE_SOURCE;
t = std::thread(muteThread, audioSource, duration, mute);
} else if (isSwitcherStatusAction(triggerAction)) {
bool stop = triggerAction == sceneTriggerAction::STOP_SWITCHER;
t = std::thread(statusThread, duration, stop);
} else {
blog(LOG_WARNING, "ignoring unkown action '%d'",
static_cast<int>(triggerAction));
}
t.detach();
}
bool SceneTrigger::checkMatch(OBSWeakSource currentScene,
OBSWeakSource previousScene)
{
switch (triggerType) {
case sceneTriggerType::NONE:
return false;
case sceneTriggerType::SCENE_ACTIVE:
return currentScene == scene;
case sceneTriggerType::SCENE_INACTIVE:
return currentScene != scene;
case sceneTriggerType::SCENE_LEAVE:
return previousScene == scene;
}
return false;
}
void SwitcherData::checkTriggers()
{
if (SceneTrigger::pause) {
return;
}
OBSSource source = obs_frontend_get_current_scene();
OBSWeakSource currentScene = obs_source_get_weak_source(source);
for (auto &t : sceneTriggers) {
if (stop && !isSwitcherStatusAction(t.triggerAction)) {
continue;
}
if (t.checkMatch(currentScene, previousScene)) {
t.logMatch();
t.performAction();
}
}
obs_source_release(source);
obs_weak_source_release(currentScene);
}
void SwitcherData::saveSceneTriggers(obs_data_t *obj)
{
obs_data_array_t *triggerArray = obs_data_array_create();
for (auto &s : sceneTriggers) {
obs_data_t *array_obj = obs_data_create();
s.save(array_obj);
obs_data_array_push_back(triggerArray, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "triggers", triggerArray);
obs_data_array_release(triggerArray);
}
void SwitcherData::loadSceneTriggers(obs_data_t *obj)
{
sceneTriggers.clear();
obs_data_array_t *triggerArray = obs_data_get_array(obj, "triggers");
size_t count = obs_data_array_count(triggerArray);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(triggerArray, i);
sceneTriggers.emplace_back();
sceneTriggers.back().load(array_obj);
obs_data_release(array_obj);
}
obs_data_array_release(triggerArray);
}
void AdvSceneSwitcher::setupTriggerTab()
{
for (auto &s : switcher->sceneTriggers) {
QListWidgetItem *item;
item = new QListWidgetItem(ui->sceneTriggers);
ui->sceneTriggers->addItem(item);
SceneTriggerWidget *sw = new SceneTriggerWidget(this, &s);
item->setSizeHint(sw->minimumSizeHint());
ui->sceneTriggers->setItemWidget(item, sw);
}
if (switcher->sceneTriggers.size() == 0) {
addPulse = PulseWidget(ui->triggerAdd, QColor(Qt::green));
ui->triggerHelp->setVisible(true);
} else {
ui->triggerHelp->setVisible(false);
}
}
void SceneTrigger::save(obs_data_t *obj)
{
obs_data_set_string(obj, "scene", GetWeakSourceName(scene).c_str());
obs_data_set_int(obj, "triggerType", static_cast<int>(triggerType));
obs_data_set_int(obj, "triggerAction", static_cast<int>(triggerAction));
obs_data_set_double(obj, "duration", duration);
obs_data_set_string(obj, "audioSource",
GetWeakSourceName(audioSource).c_str());
}
void SceneTrigger::load(obs_data_t *obj)
{
const char *sceneName = obs_data_get_string(obj, "scene");
scene = GetWeakSourceByName(sceneName);
triggerType = static_cast<sceneTriggerType>(
obs_data_get_int(obj, "triggerType"));
triggerAction = static_cast<sceneTriggerAction>(
obs_data_get_int(obj, "triggerAction"));
duration = obs_data_get_double(obj, "duration");
const char *audioSourceName = obs_data_get_string(obj, "audioSource");
audioSource = GetWeakSourceByName(audioSourceName);
}
static inline void populateTriggers(QComboBox *list)
{
AdvSceneSwitcher::addSelectionEntry(
list,
obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.none"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneActive"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneInactive"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerType.sceneLeave"));
}
inline void populateActions(QComboBox *list)
{
AdvSceneSwitcher::addSelectionEntry(
list,
obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.none"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startRecording"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.pauseRecording"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unpauseRecording"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopRecording"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startStreaming"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopStreaming"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startReplayBuffer"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopReplayBuffer"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.muteSource"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.unmuteSource"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.startSwitcher"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.sceneTriggerTab.sceneTriggerAction.stopSwitcher"));
}
SceneTriggerWidget::SceneTriggerWidget(QWidget *parent, SceneTrigger *s)
: SwitchWidget(parent, s, false, false)
{
triggers = new QComboBox();
actions = new QComboBox();
duration = new QDoubleSpinBox();
audioSources = new QComboBox();
duration->setMinimum(0.0);
duration->setMaximum(99.000000);
duration->setSuffix("s");
QWidget::connect(triggers, SIGNAL(currentIndexChanged(int)), this,
SLOT(TriggerTypeChanged(int)));
QWidget::connect(actions, SIGNAL(currentIndexChanged(int)), this,
SLOT(TriggerActionChanged(int)));
QWidget::connect(duration, SIGNAL(valueChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(audioSources,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(AudioSourceChanged(const QString &)));
populateTriggers(triggers);
populateActions(actions);
AdvSceneSwitcher::populateAudioSelection(audioSources);
if (s) {
triggers->setCurrentIndex(static_cast<int>(s->triggerType));
actions->setCurrentIndex(static_cast<int>(s->triggerAction));
duration->setValue(s->duration);
audioSources->setCurrentText(
GetWeakSourceName(s->audioSource).c_str());
if (isAudioAction(s->triggerAction)) {
audioSources->show();
} else {
audioSources->hide();
}
}
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{triggers}}", triggers},
{"{{actions}}", actions},
{"{{audioSources}}", audioSources},
{"{{duration}}", duration},
{"{{scenes}}", scenes}};
placeWidgets(obs_module_text("AdvSceneSwitcher.sceneTriggerTab.entry"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
switchData = s;
loading = false;
}
SceneTrigger *SceneTriggerWidget::getSwitchData()
{
return switchData;
}
void SceneTriggerWidget::setSwitchData(SceneTrigger *s)
{
switchData = s;
}
void SceneTriggerWidget::swapSwitchData(SceneTriggerWidget *s1,
SceneTriggerWidget *s2)
{
SwitchWidget::swapSwitchData(s1, s2);
SceneTrigger *t = s1->getSwitchData();
s1->setSwitchData(s2->getSwitchData());
s2->setSwitchData(t);
}
void SceneTriggerWidget::TriggerTypeChanged(int index)
{
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->triggerType = static_cast<sceneTriggerType>(index);
}
void SceneTriggerWidget::TriggerActionChanged(int index)
{
if (loading || !switchData) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
switchData->triggerAction =
static_cast<sceneTriggerAction>(index);
}
if (isAudioAction(switchData->triggerAction)) {
audioSources->show();
} else {
audioSources->hide();
}
}
void SceneTriggerWidget::DurationChanged(double dur)
{
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->duration = dur;
}
void SceneTriggerWidget::AudioSourceChanged(const QString &text)
{
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->audioSource = GetWeakSourceByQString(text);
}

131
src/screenshot-helper.cpp Normal file
View File

@@ -0,0 +1,131 @@
#include "headers/screenshot-helper.hpp"
static void ScreenshotTick(void *param, float);
AdvSSScreenshotObj::AdvSSScreenshotObj(obs_source_t *source)
: weakSource(OBSGetWeakRef(source))
{
obs_add_tick_callback(ScreenshotTick, this);
}
AdvSSScreenshotObj::~AdvSSScreenshotObj()
{
obs_enter_graphics();
gs_stagesurface_destroy(stagesurf);
gs_texrender_destroy(texrender);
obs_leave_graphics();
obs_remove_tick_callback(ScreenshotTick, this);
}
void AdvSSScreenshotObj::Screenshot()
{
OBSSource source = OBSGetStrongRef(weakSource);
if (source) {
cx = obs_source_get_base_width(source);
cy = obs_source_get_base_height(source);
} else {
obs_video_info ovi;
obs_get_video_info(&ovi);
cx = ovi.base_width;
cy = ovi.base_height;
}
if (!cx || !cy) {
blog(LOG_WARNING, "Cannot screenshot, invalid target size");
obs_remove_tick_callback(ScreenshotTick, this);
done = true;
return;
}
texrender = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
stagesurf = gs_stagesurface_create(cx, cy, GS_RGBA);
gs_texrender_reset(texrender);
if (gs_texrender_begin(texrender, cx, cy)) {
vec4 zero;
vec4_zero(&zero);
gs_clear(GS_CLEAR_COLOR, &zero, 0.0f, 0);
gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
gs_blend_state_push();
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
if (source) {
obs_source_inc_showing(source);
obs_source_video_render(source);
obs_source_dec_showing(source);
} else {
obs_render_main_texture();
}
gs_blend_state_pop();
gs_texrender_end(texrender);
}
}
void AdvSSScreenshotObj::Download()
{
gs_stage_texture(stagesurf, gs_texrender_get_texture(texrender));
}
void AdvSSScreenshotObj::Copy()
{
uint8_t *videoData = nullptr;
uint32_t videoLinesize = 0;
image = QImage(cx, cy, QImage::Format::Format_RGBX8888);
if (gs_stagesurface_map(stagesurf, &videoData, &videoLinesize)) {
int linesize = image.bytesPerLine();
for (int y = 0; y < (int)cy; y++)
memcpy(image.scanLine(y),
videoData + (y * videoLinesize), linesize);
gs_stagesurface_unmap(stagesurf);
}
}
void AdvSSScreenshotObj::MarkDone()
{
time = std::chrono::high_resolution_clock::now();
done = true;
}
#define STAGE_SCREENSHOT 0
#define STAGE_DOWNLOAD 1
#define STAGE_COPY_AND_SAVE 2
#define STAGE_FINISH 3
static void ScreenshotTick(void *param, float)
{
AdvSSScreenshotObj *data =
reinterpret_cast<AdvSSScreenshotObj *>(param);
if (data->stage == STAGE_FINISH) {
return;
}
obs_enter_graphics();
switch (data->stage) {
case STAGE_SCREENSHOT:
data->Screenshot();
break;
case STAGE_DOWNLOAD:
data->Download();
break;
case STAGE_COPY_AND_SAVE:
data->Copy();
data->MarkDone();
obs_remove_tick_callback(ScreenshotTick, data);
break;
}
obs_leave_graphics();
data->stage++;
}

112
src/section.cpp Normal file
View File

@@ -0,0 +1,112 @@
#include <QPropertyAnimation>
#include "headers/section.hpp"
#include "headers/utility.hpp"
Section::Section(const int animationDuration, QWidget *parent)
: QWidget(parent), _animationDuration(animationDuration)
{
_toggleButton = new QToolButton(this);
_headerLine = new QFrame(this);
_mainLayout = new QGridLayout(this);
_headerWidgetLayout = new QHBoxLayout();
_toggleButton->setStyleSheet("QToolButton {border: none;}");
_toggleButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
_toggleButton->setArrowType(Qt::ArrowType::RightArrow);
_toggleButton->setCheckable(true);
_toggleButton->setChecked(true);
_headerLine->setFrameShape(QFrame::HLine);
_headerLine->setFrameShadow(QFrame::Sunken);
_headerLine->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Maximum);
// Don't waste space
_mainLayout->setVerticalSpacing(0);
_mainLayout->setContentsMargins(0, 0, 0, 0);
// But add some spacing for widgets in header
_headerWidgetLayout->setSpacing(11);
_headerWidgetLayout->addWidget(_toggleButton);
int row = 0;
_mainLayout->addLayout(_headerWidgetLayout, row, 0, 1, 1,
Qt::AlignLeft);
_mainLayout->addWidget(_headerLine, row++, 2, 1, 1);
setLayout(_mainLayout);
connect(_toggleButton, &QToolButton::toggled, this, &Section::Collapse);
}
void Section::Collapse(bool collapsed)
{
_toggleButton->setChecked(collapsed);
_toggleButton->setArrowType(!collapsed ? Qt::ArrowType::DownArrow
: Qt::ArrowType::RightArrow);
_toggleAnimation->setDirection(!collapsed
? QAbstractAnimation::Forward
: QAbstractAnimation::Backward);
_toggleAnimation->start();
}
void Section::SetContent(QWidget *w)
{
// Clean up previous content
if (_contentArea) {
auto oldLayout = _contentArea->layout();
if (oldLayout) {
clearLayout(oldLayout);
delete oldLayout;
}
}
delete _contentArea;
delete _toggleAnimation;
// Setup contentArea
_contentArea = new QScrollArea(this);
_contentArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
// Start out collapsed
_contentArea->setMaximumHeight(0);
_contentArea->setMinimumHeight(0);
auto newLayout = new QVBoxLayout();
newLayout->addWidget(w);
_contentArea->setLayout(newLayout);
_mainLayout->addWidget(_contentArea, 1, 0, 1, 3);
// Animation Setup
_toggleAnimation = new QParallelAnimationGroup(this);
_toggleAnimation->addAnimation(
new QPropertyAnimation(this, "minimumHeight"));
_toggleAnimation->addAnimation(
new QPropertyAnimation(this, "maximumHeight"));
_toggleAnimation->addAnimation(
new QPropertyAnimation(_contentArea, "maximumHeight"));
const auto collapsedHeight =
sizeHint().height() - _contentArea->maximumHeight();
auto contentHeight = newLayout->sizeHint().height();
for (int i = 0; i < _toggleAnimation->animationCount() - 1; ++i) {
QPropertyAnimation *SectionAnimation =
static_cast<QPropertyAnimation *>(
_toggleAnimation->animationAt(i));
SectionAnimation->setDuration(_animationDuration);
SectionAnimation->setStartValue(collapsedHeight);
SectionAnimation->setEndValue(collapsedHeight + contentHeight);
}
QPropertyAnimation *contentAnimation =
static_cast<QPropertyAnimation *>(_toggleAnimation->animationAt(
_toggleAnimation->animationCount() - 1));
contentAnimation->setDuration(_animationDuration);
contentAnimation->setStartValue(0);
contentAnimation->setEndValue(contentHeight);
}
void Section::AddHeaderWidget(QWidget *w)
{
_headerWidgetLayout->addWidget(w);
}

View File

@@ -12,16 +12,20 @@ void AdvSceneSwitcher::on_audioAdd_clicked()
std::lock_guard<std::mutex> lock(switcher->m);
switcher->audioSwitches.emplace_back();
listAddClicked(ui->audioSwitches,
new AudioSwitchWidget(&switcher->audioSwitches.back()),
ui->audioAdd, &addPulse);
AudioSwitchWidget *sw =
new AudioSwitchWidget(this, &switcher->audioSwitches.back());
listAddClicked(ui->audioSwitches, sw, ui->audioAdd, &addPulse);
ui->audioHelp->setVisible(false);
}
void AdvSceneSwitcher::on_audioRemove_clicked()
{
QListWidgetItem *item = ui->audioSwitches->currentItem();
if (!item)
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
@@ -36,8 +40,9 @@ void AdvSceneSwitcher::on_audioRemove_clicked()
void AdvSceneSwitcher::on_audioUp_clicked()
{
int index = ui->audioSwitches->currentRow();
if (!listMoveUp(ui->audioSwitches))
if (!listMoveUp(ui->audioSwitches)) {
return;
}
AudioSwitchWidget *s1 =
(AudioSwitchWidget *)ui->audioSwitches->itemWidget(
@@ -57,8 +62,9 @@ void AdvSceneSwitcher::on_audioDown_clicked()
{
int index = ui->audioSwitches->currentRow();
if (!listMoveDown(ui->audioSwitches))
if (!listMoveDown(ui->audioSwitches)) {
return;
}
AudioSwitchWidget *s1 =
(AudioSwitchWidget *)ui->audioSwitches->itemWidget(
@@ -76,8 +82,10 @@ void AdvSceneSwitcher::on_audioDown_clicked()
void AdvSceneSwitcher::on_audioFallback_toggled(bool on)
{
if (loading || !switcher)
if (loading || !switcher) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->audioFallback.enable = on;
}
@@ -85,177 +93,108 @@ void AdvSceneSwitcher::on_audioFallback_toggled(bool on)
void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene,
OBSWeakSource &transition)
{
bool durationReached =
((unsigned long long)audioFallback.matchCount * interval) /
1000.0 >=
audioFallback.duration;
if (durationReached) {
scene = (audioFallback.usePreviousScene) ? previousScene
: audioFallback.scene;
if (audioFallback.duration.DurationReached()) {
scene = audioFallback.getScene();
transition = audioFallback.transition;
if (verbose)
if (verbose) {
audioFallback.logMatch();
}
}
audioFallback.matchCount++;
}
void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkAudioSwitch(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (AudioSwitch::pause)
return;
if (AudioSwitch::pause) {
return false;
}
bool fallbackChecked = false; // false if one or no match
bool match = false;
bool fallbackChecked = false; // false if only one or no match
for (AudioSwitch &s : audioSwitches) {
if (!s.initialized())
if (!s.initialized()) {
continue;
}
obs_source_t *as = obs_weak_source_get_source(s.audioSource);
bool audioActive = obs_source_active(as);
obs_source_release(as);
if (s.ignoreInactiveSource) {
obs_source_t *as =
obs_weak_source_get_source(s.audioSource);
bool audioActive = obs_source_active(as);
obs_source_release(as);
if (!audioActive) {
continue;
}
}
// peak will have a value from -60 db to 0 db
bool volumeThresholdreached = false;
if (s.condition == ABOVE)
if (s.condition == ABOVE) {
volumeThresholdreached = ((double)s.peak + 60) * 1.7 >
s.volumeThreshold;
else
} else {
volumeThresholdreached = ((double)s.peak + 60) * 1.7 <
s.volumeThreshold;
// reset for next check
s.peak = -FLT_MAX;
if (volumeThresholdreached) {
s.matchCount++;
} else {
s.matchCount = 0;
}
bool durationReached =
((unsigned long long)s.matchCount * interval) /
1000.0 >=
s.duration;
// Reset for next check
s.peak = -FLT_MAX;
if (volumeThresholdreached && durationReached && audioActive) {
if (!volumeThresholdreached) {
s.duration.Reset();
}
if (volumeThresholdreached && s.duration.DurationReached()) {
if (match) {
checkAudioSwitchFallback(scene, transition);
fallbackChecked = true;
break;
}
scene = (s.usePreviousScene) ? previousScene : s.scene;
scene = s.getScene();
transition = s.transition;
match = true;
if (verbose)
if (verbose) {
s.logMatch();
}
if (!audioFallback.enable)
if (!audioFallback.enable) {
break;
}
}
}
if (!fallbackChecked)
audioFallback.matchCount = 0;
}
if (!fallbackChecked) {
audioFallback.duration.Reset();
}
void saveAudioFallback(obs_data_t *obj, AudioSwitchFallback &audioFallback)
{
obs_source_t *fallbackSceneSource =
obs_weak_source_get_source(audioFallback.scene);
obs_source_t *fallbackTransition =
obs_weak_source_get_source(audioFallback.transition);
const char *fallbackSceneName =
obs_source_get_name(fallbackSceneSource);
const char *fallbackTransitionName =
obs_source_get_name(fallbackTransition);
obs_data_set_bool(obj, "audioFallbackEnable", audioFallback.enable);
obs_data_set_string(obj, "audioFallbackScene",
audioFallback.usePreviousScene ? previous_scene_name
: fallbackSceneName);
obs_data_set_string(obj, "audioFallbackTransition",
fallbackTransitionName);
obs_data_set_double(obj, "audioFallbackDuration",
audioFallback.duration);
obs_source_release(fallbackSceneSource);
obs_source_release(fallbackTransition);
return match;
}
void SwitcherData::saveAudioSwitches(obs_data_t *obj)
{
obs_data_array_t *audioArray = obs_data_array_create();
for (AudioSwitch &s : switcher->audioSwitches) {
for (AudioSwitch &s : audioSwitches) {
obs_data_t *array_obj = obs_data_create();
obs_source_t *sceneSource = obs_weak_source_get_source(s.scene);
obs_source_t *transition =
obs_weak_source_get_source(s.transition);
obs_source_t *audioSrouce =
obs_weak_source_get_source(s.audioSource);
if ((s.usePreviousScene || sceneSource) && transition &&
audioSrouce) {
const char *sceneName =
obs_source_get_name(sceneSource);
const char *transitionName =
obs_source_get_name(transition);
const char *audioSourceName =
obs_source_get_name(audioSrouce);
obs_data_set_string(array_obj, "scene",
s.usePreviousScene
? previous_scene_name
: sceneName);
obs_data_set_string(array_obj, "transition",
transitionName);
obs_data_set_string(array_obj, "audioSource",
audioSourceName);
obs_data_set_int(array_obj, "volume",
s.volumeThreshold);
obs_data_set_int(array_obj, "condition", s.condition);
obs_data_set_double(array_obj, "duration", s.duration);
obs_data_array_push_back(audioArray, array_obj);
}
obs_source_release(sceneSource);
obs_source_release(transition);
obs_source_release(audioSrouce);
s.save(array_obj);
obs_data_array_push_back(audioArray, array_obj);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "audioSwitches", audioArray);
obs_data_array_release(audioArray);
saveAudioFallback(obj, audioFallback);
}
void loadAudioFallback(obs_data_t *obj, AudioSwitchFallback &audioFallback)
{
const char *fallbackSceneName =
obs_data_get_string(obj, "audioFallbackScene");
const char *fallbackTransitionName =
obs_data_get_string(obj, "audioFallbackTransition");
audioFallback.enable = obs_data_get_bool(obj, "audioFallbackEnable");
audioFallback.duration =
obs_data_get_double(obj, "audioFallbackDuration");
audioFallback.scene = GetWeakSourceByName(fallbackSceneName);
audioFallback.transition =
GetWeakTransitionByName(fallbackTransitionName);
audioFallback.usePreviousScene =
strcmp(fallbackSceneName, previous_scene_name) == 0;
audioFallback.save(obj);
}
void SwitcherData::loadAudioSwitches(obs_data_t *obj)
{
switcher->audioSwitches.clear();
audioSwitches.clear();
obs_data_array_t *audioArray = obs_data_get_array(obj, "audioSwitches");
size_t count = obs_data_array_count(audioArray);
@@ -263,27 +202,14 @@ void SwitcherData::loadAudioSwitches(obs_data_t *obj)
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(audioArray, i);
const char *scene = obs_data_get_string(array_obj, "scene");
const char *transition =
obs_data_get_string(array_obj, "transition");
const char *audioSource =
obs_data_get_string(array_obj, "audioSource");
int vol = obs_data_get_int(array_obj, "volume");
audioCondition condition = (audioCondition)obs_data_get_int(
array_obj, "condition");
double duration = obs_data_get_double(array_obj, "duration");
switcher->audioSwitches.emplace_back(
GetWeakSourceByName(scene),
GetWeakTransitionByName(transition),
GetWeakSourceByName(audioSource), vol, condition,
duration, (strcmp(scene, previous_scene_name) == 0));
audioSwitches.emplace_back();
audioSwitches.back().load(array_obj);
obs_data_release(array_obj);
}
obs_data_array_release(audioArray);
loadAudioFallback(obj, audioFallback);
audioFallback.load(obj);
}
void AdvSceneSwitcher::setupAudioTab()
@@ -292,16 +218,20 @@ void AdvSceneSwitcher::setupAudioTab()
QListWidgetItem *item;
item = new QListWidgetItem(ui->audioSwitches);
ui->audioSwitches->addItem(item);
AudioSwitchWidget *sw = new AudioSwitchWidget(&s);
AudioSwitchWidget *sw = new AudioSwitchWidget(this, &s);
item->setSizeHint(sw->minimumSizeHint());
ui->audioSwitches->setItemWidget(item, sw);
}
if (switcher->audioSwitches.size() == 0)
if (switcher->audioSwitches.size() == 0) {
addPulse = PulseWidget(ui->audioAdd, QColor(Qt::green));
ui->audioHelp->setVisible(true);
} else {
ui->audioHelp->setVisible(false);
}
AudioSwitchFallbackWidget *fb =
new AudioSwitchFallbackWidget(&switcher->audioFallback);
new AudioSwitchFallbackWidget(this, &switcher->audioFallback);
ui->audioFallbackLayout->addWidget(fb);
ui->audioFallback->setChecked(switcher->audioFallback.enable);
}
@@ -315,9 +245,11 @@ void AudioSwitch::setVolumeLevel(void *data,
UNUSED_PARAMETER(inputPeak);
AudioSwitch *s = static_cast<AudioSwitch *>(data);
for (int i = 1; i < MAX_AUDIO_CHANNELS; i++)
if (peak[i] > s->peak)
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++) {
if (peak[i] > s->peak) {
s->peak = peak[i];
}
}
}
obs_volmeter_t *AddVolmeterToSource(AudioSwitch *entry, obs_weak_source *source)
@@ -354,22 +286,57 @@ bool AudioSwitch::valid()
(SceneSwitcherEntry::valid() && WeakSourceValid(audioSource));
}
AudioSwitch::AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
OBSWeakSource audioSource_, int volumeThreshold_,
audioCondition condition_, double duration_,
bool usePreviousScene_)
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
audioSource(audioSource_),
volumeThreshold(volumeThreshold_),
condition(condition_),
duration(duration_)
void AudioSwitch::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj);
obs_data_set_string(obj, "audioSource",
GetWeakSourceName(audioSource).c_str());
obs_data_set_int(obj, "volume", volumeThreshold);
obs_data_set_int(obj, "condition", condition);
duration.Save(obj, "duration");
obs_data_set_bool(obj, "ignoreInactiveSource", ignoreInactiveSource);
}
void AudioSwitch::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj);
const char *audioSourceName = obs_data_get_string(obj, "audioSource");
audioSource = GetWeakSourceByName(audioSourceName);
volumeThreshold = obs_data_get_int(obj, "volume");
condition = (audioCondition)obs_data_get_int(obj, "condition");
duration.Load(obj, "duration");
ignoreInactiveSource = obs_data_get_bool(obj, "ignoreInactiveSource");
volmeter = AddVolmeterToSource(this, audioSource);
}
void AudioSwitchFallback::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj, "audioFallbackTargetType",
"audioFallbackScene",
"audioFallbackTransition");
obs_data_set_bool(obj, "audioFallbackEnable", enable);
duration.Save(obj, "audioFallbackDuration");
}
void AudioSwitchFallback::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj, "audioFallbackTargetType",
"audioFallbackScene",
"audioFallbackTransition");
enable = obs_data_get_bool(obj, "audioFallbackEnable");
duration.Load(obj, "audioFallbackDuration");
}
AudioSwitch::AudioSwitch(const AudioSwitch &other)
: SceneSwitcherEntry(other.scene, other.transition,
other.usePreviousScene),
: SceneSwitcherEntry(other.targetType, other.group, other.scene,
other.transition, other.usePreviousScene),
audioSource(other.audioSource),
volumeThreshold(other.volumeThreshold),
condition(other.condition),
@@ -379,8 +346,8 @@ AudioSwitch::AudioSwitch(const AudioSwitch &other)
}
AudioSwitch::AudioSwitch(AudioSwitch &&other)
: SceneSwitcherEntry(other.scene, other.transition,
other.usePreviousScene),
: SceneSwitcherEntry(other.targetType, other.group, other.scene,
other.transition, other.usePreviousScene),
audioSource(other.audioSource),
volumeThreshold(other.volumeThreshold),
condition(other.condition),
@@ -420,6 +387,8 @@ AudioSwitch &AudioSwitch::operator=(AudioSwitch &&other) noexcept
void swap(AudioSwitch &first, AudioSwitch &second)
{
std::swap(first.targetType, second.targetType);
std::swap(first.group, second.group);
std::swap(first.scene, second.scene);
std::swap(first.transition, second.transition);
std::swap(first.usePreviousScene, second.usePreviousScene);
@@ -433,7 +402,7 @@ void swap(AudioSwitch &first, AudioSwitch &second)
second.resetVolmeter();
}
void populateConditionSelection(QComboBox *list)
static inline void populateConditionSelection(QComboBox *list)
{
list->addItem(
obs_module_text("AdvSceneSwitcher.audioTab.condition.above"));
@@ -441,27 +410,27 @@ void populateConditionSelection(QComboBox *list)
obs_module_text("AdvSceneSwitcher.audioTab.condition.below"));
}
AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) : SwitchWidget(s)
AudioSwitchWidget::AudioSwitchWidget(QWidget *parent, AudioSwitch *s)
: SwitchWidget(parent, s, true, true)
{
audioSources = new QComboBox();
condition = new QComboBox();
audioVolumeThreshold = new QSpinBox();
duration = new QDoubleSpinBox();
duration = new DurationSelection(this, false);
ignoreInactiveSource = new QCheckBox(obs_module_text(
"AdvSceneSwitcher.audioTab.ignoreInactiveSource"));
obs_source_t *soruce = nullptr;
if (s)
soruce = obs_weak_source_get_source(s->audioSource);
volMeter = new VolControl(soruce);
obs_source_release(soruce);
obs_source_t *source = nullptr;
if (s) {
source = obs_weak_source_get_source(s->audioSource);
}
volMeter = new VolControl(source);
obs_source_release(source);
audioVolumeThreshold->setSuffix("%");
audioVolumeThreshold->setMaximum(100);
audioVolumeThreshold->setMinimum(0);
duration->setMinimum(0.0);
duration->setMaximum(99.000000);
duration->setSuffix("s");
QWidget::connect(volMeter->GetSlider(), SIGNAL(valueChanged(int)),
audioVolumeThreshold, SLOT(setValue(int)));
QWidget::connect(audioVolumeThreshold, SIGNAL(valueChanged(int)),
@@ -470,11 +439,13 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) : SwitchWidget(s)
SLOT(VolumeThresholdChanged(int)));
QWidget::connect(condition, SIGNAL(currentIndexChanged(int)), this,
SLOT(ConditionChanged(int)));
QWidget::connect(duration, SIGNAL(valueChanged(double)), this,
QWidget::connect(duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
QWidget::connect(audioSources,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SourceChanged(const QString &)));
QWidget::connect(ignoreInactiveSource, SIGNAL(stateChanged(int)), this,
SLOT(IgnoreInactiveChanged(int)));
AdvSceneSwitcher::populateAudioSelection(audioSources);
populateConditionSelection(condition);
@@ -484,7 +455,8 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) : SwitchWidget(s)
GetWeakSourceName(s->audioSource).c_str());
audioVolumeThreshold->setValue(s->volumeThreshold);
condition->setCurrentIndex(s->condition);
duration->setValue(s->duration);
duration->SetDuration(s->duration);
ignoreInactiveSource->setChecked(s->ignoreInactiveSource);
}
QHBoxLayout *switchLayout = new QHBoxLayout;
@@ -493,6 +465,7 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) : SwitchWidget(s)
{"{{volumeWidget}}", audioVolumeThreshold},
{"{{condition}}", condition},
{"{{duration}}", duration},
{"{{ignoreInactiveSource}}", ignoreInactiveSource},
{"{{scenes}}", scenes},
{"{{transitions}}", transitions}};
placeWidgets(obs_module_text("AdvSceneSwitcher.audioTab.entry"),
@@ -552,8 +525,10 @@ void AudioSwitchWidget::UpdateVolmeterSource()
void AudioSwitchWidget::SourceChanged(const QString &text)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->audioSource = GetWeakSourceByQString(text);
switchData->resetVolmeter();
@@ -562,42 +537,55 @@ void AudioSwitchWidget::SourceChanged(const QString &text)
void AudioSwitchWidget::VolumeThresholdChanged(int vol)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->volumeThreshold = vol;
}
void AudioSwitchWidget::ConditionChanged(int cond)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->condition = (audioCondition)cond;
}
void AudioSwitchWidget::DurationChanged(double dur)
void AudioSwitchWidget::DurationChanged(double sec)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->duration = dur;
switchData->duration.seconds = sec;
}
AudioSwitchFallbackWidget::AudioSwitchFallbackWidget(AudioSwitchFallback *s)
: SwitchWidget(s)
void AudioSwitchWidget::IgnoreInactiveChanged(int state)
{
duration = new QDoubleSpinBox();
if (loading || !switchData) {
return;
}
duration->setMinimum(0.0);
duration->setMaximum(99.000000);
duration->setSuffix("s");
std::lock_guard<std::mutex> lock(switcher->m);
switchData->ignoreInactiveSource = state;
}
QWidget::connect(duration, SIGNAL(valueChanged(double)), this,
AudioSwitchFallbackWidget::AudioSwitchFallbackWidget(QWidget *parent,
AudioSwitchFallback *s)
: SwitchWidget(parent, s, true, true)
{
duration = new DurationSelection(this, false);
QWidget::connect(duration, SIGNAL(DurationChanged(double)), this,
SLOT(DurationChanged(double)));
if (s) {
duration->setValue(s->duration);
duration->SetDuration(s->duration);
}
QHBoxLayout *mainLayout = new QHBoxLayout;
@@ -615,10 +603,12 @@ AudioSwitchFallbackWidget::AudioSwitchFallbackWidget(AudioSwitchFallback *s)
loading = false;
}
void AudioSwitchFallbackWidget::DurationChanged(double dur)
void AudioSwitchFallbackWidget::DurationChanged(double sec)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->duration = dur;
switchData->duration.seconds = sec;
}

View File

@@ -11,15 +11,18 @@ void AdvSceneSwitcher::on_executableAdd_clicked()
listAddClicked(ui->executables,
new ExecutableSwitchWidget(
&switcher->executableSwitches.back()),
this, &switcher->executableSwitches.back()),
ui->executableAdd, &addPulse);
ui->exeHelp->setVisible(false);
}
void AdvSceneSwitcher::on_executableRemove_clicked()
{
QListWidgetItem *item = ui->executables->currentItem();
if (!item)
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
@@ -34,8 +37,9 @@ void AdvSceneSwitcher::on_executableRemove_clicked()
void AdvSceneSwitcher::on_executableUp_clicked()
{
int index = ui->executables->currentRow();
if (!listMoveUp(ui->executables))
if (!listMoveUp(ui->executables)) {
return;
}
ExecutableSwitchWidget *s1 =
(ExecutableSwitchWidget *)ui->executables->itemWidget(
@@ -55,8 +59,9 @@ void AdvSceneSwitcher::on_executableDown_clicked()
{
int index = ui->executables->currentRow();
if (!listMoveDown(ui->executables))
if (!listMoveDown(ui->executables)) {
return;
}
ExecutableSwitchWidget *s1 =
(ExecutableSwitchWidget *)ui->executables->itemWidget(
@@ -72,15 +77,17 @@ void AdvSceneSwitcher::on_executableDown_clicked()
switcher->executableSwitches[index + 1]);
}
void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkExeSwitch(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (executableSwitches.size() == 0 || ExecutableSwitch::pause)
return;
if (executableSwitches.size() == 0 || ExecutableSwitch::pause) {
return false;
}
std::string title;
QStringList runningProcesses;
bool ignored = false;
bool match = false;
// Check if current window is ignored
GetCurrentWindowTitle(title);
@@ -103,15 +110,15 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene,
// Check for match
GetProcessList(runningProcesses);
for (ExecutableSwitch &s : executableSwitches) {
if (!s.initialized())
if (!s.initialized()) {
continue;
// True if executable switch is running (direct)
}
bool equals = runningProcesses.contains(s.exe);
// True if executable switch is running (regex)
bool matches = (runningProcesses.indexOf(
QRegularExpression(s.exe)) != -1);
// True if focus is disabled OR switch is focused
bool focus = (!s.inFocus || isInFocus(s.exe));
// True if current window is ignored AND switch equals OR matches last window
bool ignore =
(ignored && (title == s.exe.toStdString() ||
@@ -120,40 +127,28 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene,
if ((equals || matches) && (focus || ignore)) {
match = true;
scene = s.scene;
scene = s.getScene();
transition = s.transition;
if (verbose)
if (verbose) {
s.logMatch();
}
break;
}
}
return match;
}
void SwitcherData::saveExecutableSwitches(obs_data_t *obj)
{
obs_data_array_t *executableArray = obs_data_array_create();
for (ExecutableSwitch &s : switcher->executableSwitches) {
for (ExecutableSwitch &s : executableSwitches) {
obs_data_t *array_obj = obs_data_create();
obs_source_t *source = obs_weak_source_get_source(s.scene);
obs_source_t *transition =
obs_weak_source_get_source(s.transition);
s.save(array_obj);
obs_data_array_push_back(executableArray, array_obj);
if (source && transition) {
const char *sceneName = obs_source_get_name(source);
const char *transitionName =
obs_source_get_name(transition);
obs_data_set_string(array_obj, "scene", sceneName);
obs_data_set_string(array_obj, "transition",
transitionName);
obs_data_set_string(array_obj, "exefile",
s.exe.toUtf8());
obs_data_set_bool(array_obj, "infocus", s.inFocus);
obs_data_array_push_back(executableArray, array_obj);
}
obs_source_release(source);
obs_source_release(transition);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "executableSwitches", executableArray);
@@ -162,7 +157,7 @@ void SwitcherData::saveExecutableSwitches(obs_data_t *obj)
void SwitcherData::loadExecutableSwitches(obs_data_t *obj)
{
switcher->executableSwitches.clear();
executableSwitches.clear();
obs_data_array_t *executableArray =
obs_data_get_array(obj, "executableSwitches");
@@ -171,15 +166,8 @@ void SwitcherData::loadExecutableSwitches(obs_data_t *obj)
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(executableArray, i);
const char *scene = obs_data_get_string(array_obj, "scene");
const char *transition =
obs_data_get_string(array_obj, "transition");
const char *exe = obs_data_get_string(array_obj, "exefile");
bool infocus = obs_data_get_bool(array_obj, "infocus");
switcher->executableSwitches.emplace_back(
GetWeakSourceByName(scene),
GetWeakTransitionByName(transition), exe, infocus);
executableSwitches.emplace_back();
executableSwitches.back().load(array_obj);
obs_data_release(array_obj);
}
@@ -192,17 +180,39 @@ void AdvSceneSwitcher::setupExecutableTab()
QListWidgetItem *item;
item = new QListWidgetItem(ui->executables);
ui->executables->addItem(item);
ExecutableSwitchWidget *sw = new ExecutableSwitchWidget(&s);
ExecutableSwitchWidget *sw =
new ExecutableSwitchWidget(this, &s);
item->setSizeHint(sw->minimumSizeHint());
ui->executables->setItemWidget(item, sw);
}
if (switcher->executableSwitches.size() == 0)
if (switcher->executableSwitches.size() == 0) {
addPulse = PulseWidget(ui->executableAdd, QColor(Qt::green));
ui->exeHelp->setVisible(true);
} else {
ui->exeHelp->setVisible(false);
}
}
ExecutableSwitchWidget::ExecutableSwitchWidget(ExecutableSwitch *s)
: SwitchWidget(s, false)
void ExecutableSwitch::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj);
obs_data_set_string(obj, "exefile", exe.toUtf8());
obs_data_set_bool(obj, "infocus", inFocus);
}
void ExecutableSwitch::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj);
exe = obs_data_get_string(obj, "exefile");
inFocus = obs_data_get_bool(obj, "infocus");
}
ExecutableSwitchWidget::ExecutableSwitchWidget(QWidget *parent,
ExecutableSwitch *s)
: SwitchWidget(parent, s, true, true)
{
processes = new QComboBox();
requiresFocus = new QCheckBox(obs_module_text(
@@ -260,16 +270,20 @@ void ExecutableSwitchWidget::swapSwitchData(ExecutableSwitchWidget *s1,
void ExecutableSwitchWidget::ProcessChanged(const QString &text)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->exe = text;
}
void ExecutableSwitchWidget::FocusChanged(int state)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->inFocus = state;
}

View File

@@ -19,14 +19,16 @@ void AdvSceneSwitcher::on_browseButton_clicked()
tr(obs_module_text("AdvSceneSwitcher.fileTab.selectWrite")),
QDir::currentPath(),
tr(obs_module_text("AdvSceneSwitcher.fileTab.textFileType")));
if (!path.isEmpty())
if (!path.isEmpty()) {
ui->writePathLineEdit->setText(path);
}
}
void AdvSceneSwitcher::on_readFileCheckBox_stateChanged(int state)
{
if (loading)
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (!state) {
@@ -42,8 +44,9 @@ void AdvSceneSwitcher::on_readFileCheckBox_stateChanged(int state)
void AdvSceneSwitcher::on_readPathLineEdit_textChanged(const QString &text)
{
if (loading)
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (text.isEmpty()) {
@@ -56,8 +59,9 @@ void AdvSceneSwitcher::on_readPathLineEdit_textChanged(const QString &text)
void AdvSceneSwitcher::on_writePathLineEdit_textChanged(const QString &text)
{
if (loading)
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (text.isEmpty()) {
@@ -75,14 +79,16 @@ void AdvSceneSwitcher::on_browseButton_2_clicked()
tr(obs_module_text("AdvSceneSwitcher.fileTab.selectRead")),
QDir::currentPath(),
tr(obs_module_text("AdvSceneSwitcher.fileTab.anyFileType")));
if (!path.isEmpty())
if (!path.isEmpty()) {
ui->readPathLineEdit->setText(path);
}
}
void SwitcherData::writeSceneInfoToFile()
{
if (!fileIO.writeEnabled || fileIO.writePath.empty())
if (!fileIO.writeEnabled || fileIO.writePath.empty()) {
return;
}
obs_source_t *currentSource = obs_frontend_get_current_scene();
@@ -97,8 +103,9 @@ void SwitcherData::writeSceneInfoToFile()
void SwitcherData::writeToStatusFile(QString msg)
{
if (!fileIO.writeEnabled || fileIO.writePath.empty())
if (!fileIO.writeEnabled || fileIO.writePath.empty()) {
return;
}
QFile file(QString::fromStdString(fileIO.writePath));
if (file.open(QIODevice::ReadWrite)) {
@@ -108,31 +115,43 @@ void SwitcherData::writeToStatusFile(QString msg)
file.close();
}
void SwitcherData::checkSwitchInfoFromFile(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkSwitchInfoFromFile(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (!fileIO.readEnabled || fileIO.readPath.empty())
return;
if (!fileIO.readEnabled || fileIO.readPath.empty() ||
FileSwitch::pause) {
return false;
}
QFile file(QString::fromStdString(fileIO.readPath));
if (file.open(QIODevice::ReadOnly)) {
QTextStream in(&file);
QString sceneStr = in.readLine();
obs_source_t *sceneRead =
obs_get_source_by_name(sceneStr.toUtf8().constData());
if (sceneRead) {
obs_weak_source_t *sceneReadWs =
obs_source_get_weak_source(sceneRead);
match = true;
scene = sceneReadWs;
transition = nullptr;
obs_weak_source_release(sceneReadWs);
obs_source_release(sceneRead);
}
file.close();
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
bool match = false;
QTextStream in(&file);
QString sceneStr = in.readLine();
OBSWeakSource sceneRead = GetWeakSourceByQString(sceneStr);
QString transitionStr = in.readLine();
OBSWeakSource transitionRead =
GetWeakTransitionByQString(transitionStr);
if (sceneRead) {
match = true;
scene = sceneRead;
transition = transitionRead;
vblog(LOG_INFO,
"match for 'file' - read scene '%s' and transition '%s' from file '%s'",
sceneStr.toUtf8().constData(),
transitionStr.toUtf8().constData(),
fileIO.readPath.c_str());
}
file.close();
return match;
}
static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
@@ -142,7 +161,7 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
return size * nmemb;
}
std::string getRemoteData(std::string &url)
static std::string getRemoteData(std::string &url)
{
std::string readBuffer;
@@ -156,37 +175,13 @@ std::string getRemoteData(std::string &url)
return readBuffer;
}
bool compareIgnoringLineEnding(QString &s1, QString &s2)
{
/*
Im using QTextStream here so the conversion between different lineendings is done by QT.
QT itself uses only the linefeed internally so the input by the user is always using that,
but the files selected by the user might use different line endings.
If you are reading this and know of a cleaner way to do this, please let me know :)
*/
QTextStream s1stream(&s1);
QTextStream s2stream(&s2);
while (!s1stream.atEnd() || !s2stream.atEnd()) {
QString s1s = s1stream.readLine();
QString s2s = s2stream.readLine();
if (s1s != s2s) {
return false;
}
}
if (!s1stream.atEnd() && !s2stream.atEnd())
return false;
return true;
}
bool matchFileContent(QString &filedata, FileSwitch &s)
{
if (s.onlyMatchIfChanged) {
size_t newHash = strHash(filedata.toUtf8().constData());
if (newHash == s.lastHash)
if (newHash == s.lastHash) {
return false;
}
s.lastHash = newHash;
}
@@ -210,13 +205,15 @@ bool checkLocalFileContent(FileSwitch &s)
{
QString t = QString::fromStdString(s.text);
QFile file(QString::fromStdString(s.file));
if (s.file.empty() || !file.open(QIODevice::ReadOnly))
if (s.file.empty() || !file.open(QIODevice::ReadOnly)) {
return false;
}
if (s.useTime) {
QDateTime newLastMod = QFileInfo(file).lastModified();
if (s.lastMod == newLastMod)
if (s.lastMod == newLastMod) {
return false;
}
s.lastMod = newLastMod;
}
@@ -227,15 +224,18 @@ bool checkLocalFileContent(FileSwitch &s)
return match;
}
void SwitcherData::checkFileContent(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkFileContent(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (FileSwitch::pause)
return;
if (FileSwitch::pause) {
return false;
}
bool match = false;
for (FileSwitch &s : fileSwitches) {
if (!s.initialized())
if (!s.initialized()) {
continue;
}
bool equal = false;
if (s.remote) {
@@ -245,15 +245,17 @@ void SwitcherData::checkFileContent(bool &match, OBSWeakSource &scene,
}
if (equal) {
scene = s.scene;
scene = s.getScene();
transition = s.transition;
match = true;
if (verbose)
if (verbose) {
s.logMatch();
}
break;
}
}
return match;
}
void AdvSceneSwitcher::on_fileAdd_clicked()
@@ -262,15 +264,19 @@ void AdvSceneSwitcher::on_fileAdd_clicked()
switcher->fileSwitches.emplace_back();
listAddClicked(ui->fileSwitches,
new FileSwitchWidget(&switcher->fileSwitches.back()),
new FileSwitchWidget(this,
&switcher->fileSwitches.back()),
ui->fileAdd, &addPulse);
ui->fileHelp->setVisible(false);
}
void AdvSceneSwitcher::on_fileRemove_clicked()
{
QListWidgetItem *item = ui->fileSwitches->currentItem();
if (!item)
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
@@ -284,27 +290,32 @@ void AdvSceneSwitcher::on_fileRemove_clicked()
void AdvSceneSwitcher::on_fileSwitches_currentRowChanged(int idx)
{
if (loading)
if (loading) {
return;
if (idx == -1)
}
if (idx == -1) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if ((int)switcher->fileSwitches.size() <= idx)
if ((int)switcher->fileSwitches.size() <= idx) {
return;
}
FileSwitch s = switcher->fileSwitches[idx];
if (s.remote)
if (s.remote) {
ui->remoteFileWarningLabel->show();
else
} else {
ui->remoteFileWarningLabel->hide();
}
}
void AdvSceneSwitcher::on_fileUp_clicked()
{
int index = ui->fileSwitches->currentRow();
if (!listMoveUp(ui->fileSwitches))
if (!listMoveUp(ui->fileSwitches)) {
return;
}
FileSwitchWidget *s1 = (FileSwitchWidget *)ui->fileSwitches->itemWidget(
ui->fileSwitches->item(index));
@@ -322,8 +333,9 @@ void AdvSceneSwitcher::on_fileDown_clicked()
{
int index = ui->fileSwitches->currentRow();
if (!listMoveDown(ui->fileSwitches))
if (!listMoveDown(ui->fileSwitches)) {
return;
}
FileSwitchWidget *s1 = (FileSwitchWidget *)ui->fileSwitches->itemWidget(
ui->fileSwitches->item(index));
@@ -340,78 +352,45 @@ void AdvSceneSwitcher::on_fileDown_clicked()
void SwitcherData::saveFileSwitches(obs_data_t *obj)
{
obs_data_array_t *fileArray = obs_data_array_create();
for (FileSwitch &s : switcher->fileSwitches) {
for (FileSwitch &s : fileSwitches) {
obs_data_t *array_obj = obs_data_create();
obs_source_t *source = obs_weak_source_get_source(s.scene);
obs_source_t *transition =
obs_weak_source_get_source(s.transition);
s.save(array_obj);
obs_data_array_push_back(fileArray, array_obj);
if (source && transition) {
const char *sceneName = obs_source_get_name(source);
const char *transitionName =
obs_source_get_name(transition);
obs_data_set_string(array_obj, "scene", sceneName);
obs_data_set_string(array_obj, "transition",
transitionName);
obs_data_set_string(array_obj, "file", s.file.c_str());
obs_data_set_string(array_obj, "text", s.text.c_str());
obs_data_set_bool(array_obj, "remote", s.remote);
obs_data_set_bool(array_obj, "useRegex", s.useRegex);
obs_data_set_bool(array_obj, "useTime", s.useTime);
obs_data_set_bool(array_obj, "onlyMatchIfChanged",
s.onlyMatchIfChanged);
obs_data_array_push_back(fileArray, array_obj);
}
obs_source_release(source);
obs_source_release(transition);
obs_data_release(array_obj);
}
obs_data_set_array(obj, "fileSwitches", fileArray);
obs_data_array_release(fileArray);
obs_data_set_bool(obj, "readEnabled", switcher->fileIO.readEnabled);
obs_data_set_string(obj, "readPath", switcher->fileIO.readPath.c_str());
obs_data_set_bool(obj, "writeEnabled", switcher->fileIO.writeEnabled);
obs_data_set_string(obj, "writePath",
switcher->fileIO.writePath.c_str());
obs_data_set_bool(obj, "readEnabled", fileIO.readEnabled);
obs_data_set_string(obj, "readPath", fileIO.readPath.c_str());
obs_data_set_bool(obj, "writeEnabled", fileIO.writeEnabled);
obs_data_set_string(obj, "writePath", fileIO.writePath.c_str());
}
void SwitcherData::loadFileSwitches(obs_data_t *obj)
{
switcher->fileSwitches.clear();
fileSwitches.clear();
obs_data_array_t *fileArray = obs_data_get_array(obj, "fileSwitches");
size_t count = obs_data_array_count(fileArray);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(fileArray, i);
const char *scene = obs_data_get_string(array_obj, "scene");
const char *transition =
obs_data_get_string(array_obj, "transition");
const char *file = obs_data_get_string(array_obj, "file");
const char *text = obs_data_get_string(array_obj, "text");
bool remote = obs_data_get_bool(array_obj, "remote");
bool useRegex = obs_data_get_bool(array_obj, "useRegex");
bool useTime = obs_data_get_bool(array_obj, "useTime");
bool onlyMatchIfChanged =
obs_data_get_bool(array_obj, "onlyMatchIfChanged");
switcher->fileSwitches.emplace_back(
GetWeakSourceByName(scene),
GetWeakTransitionByName(transition), file, text, remote,
useRegex, useTime, onlyMatchIfChanged);
fileSwitches.emplace_back();
fileSwitches.back().load(array_obj);
obs_data_release(array_obj);
}
obs_data_array_release(fileArray);
obs_data_set_default_bool(obj, "readEnabled", false);
switcher->fileIO.readEnabled = obs_data_get_bool(obj, "readEnabled");
switcher->fileIO.readPath = obs_data_get_string(obj, "readPath");
fileIO.readEnabled = obs_data_get_bool(obj, "readEnabled");
fileIO.readPath = obs_data_get_string(obj, "readPath");
obs_data_set_default_bool(obj, "writeEnabled", false);
switcher->fileIO.writeEnabled = obs_data_get_bool(obj, "writeEnabled");
switcher->fileIO.writePath = obs_data_get_string(obj, "writePath");
fileIO.writeEnabled = obs_data_get_bool(obj, "writeEnabled");
fileIO.writePath = obs_data_get_string(obj, "writePath");
}
void AdvSceneSwitcher::setupFileTab()
@@ -422,20 +401,25 @@ void AdvSceneSwitcher::setupFileTab()
obs_module_text("AdvSceneSwitcher.fileTab.remoteFileWarning2"));
ui->remoteFileWarningLabel->hide();
if (switcher->curl)
if (switcher->curl) {
ui->libcurlWarning->setVisible(false);
}
for (auto &s : switcher->fileSwitches) {
QListWidgetItem *item;
item = new QListWidgetItem(ui->fileSwitches);
ui->fileSwitches->addItem(item);
FileSwitchWidget *sw = new FileSwitchWidget(&s);
FileSwitchWidget *sw = new FileSwitchWidget(this, &s);
item->setSizeHint(sw->minimumSizeHint());
ui->fileSwitches->setItemWidget(item, sw);
}
if (switcher->fileSwitches.size() == 0)
if (switcher->fileSwitches.size() == 0) {
addPulse = PulseWidget(ui->fileAdd, QColor(Qt::green));
ui->fileHelp->setVisible(true);
} else {
ui->fileHelp->setVisible(false);
}
ui->readPathLineEdit->setText(
QString::fromStdString(switcher->fileIO.readPath.c_str()));
@@ -452,7 +436,32 @@ void AdvSceneSwitcher::setupFileTab()
}
}
FileSwitchWidget::FileSwitchWidget(FileSwitch *s) : SwitchWidget(s, false)
void FileSwitch::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj);
obs_data_set_string(obj, "file", file.c_str());
obs_data_set_string(obj, "text", text.c_str());
obs_data_set_bool(obj, "remote", remote);
obs_data_set_bool(obj, "useRegex", useRegex);
obs_data_set_bool(obj, "useTime", useTime);
obs_data_set_bool(obj, "onlyMatchIfChanged", onlyMatchIfChanged);
}
void FileSwitch::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj);
file = obs_data_get_string(obj, "file");
text = obs_data_get_string(obj, "text");
remote = obs_data_get_bool(obj, "remote");
useRegex = obs_data_get_bool(obj, "useRegex");
useTime = obs_data_get_bool(obj, "useTime");
onlyMatchIfChanged = obs_data_get_bool(obj, "onlyMatchIfChanged");
}
FileSwitchWidget::FileSwitchWidget(QWidget *parent, FileSwitch *s)
: SwitchWidget(parent, s, true, true)
{
fileType = new QComboBox();
filePath = new QLineEdit();
@@ -486,10 +495,11 @@ FileSwitchWidget::FileSwitchWidget(FileSwitch *s) : SwitchWidget(s, false)
fileType->addItem(obs_module_text("AdvSceneSwitcher.fileTab.remote"));
if (s) {
if (s->remote)
if (s->remote) {
fileType->setCurrentIndex(1);
else
} else {
fileType->setCurrentIndex(0);
}
filePath->setText(QString::fromStdString(s->file));
matchText->setPlainText(QString::fromStdString(s->text));
useRegex->setChecked(s->useRegex);
@@ -551,8 +561,9 @@ void FileSwitchWidget::swapSwitchData(FileSwitchWidget *s1,
void FileSwitchWidget::FileTypeChanged(int index)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
if ((file_type)index == LOCAL) {
browseButton->setDisabled(false);
@@ -568,24 +579,28 @@ void FileSwitchWidget::FileTypeChanged(int index)
void FileSwitchWidget::FilePathChanged()
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->file = filePath->text().toUtf8().constData();
}
void FileSwitchWidget::BrowseButtonClicked()
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
QString path = QFileDialog::getOpenFileName(
this,
tr(obs_module_text("AdvSceneSwitcher.fileTab.selectRead")),
QDir::currentPath(),
tr(obs_module_text("AdvSceneSwitcher.fileTab.anyFileType")));
if (path.isEmpty())
if (path.isEmpty()) {
return;
}
filePath->setText(path);
FilePathChanged();
@@ -593,32 +608,40 @@ void FileSwitchWidget::BrowseButtonClicked()
void FileSwitchWidget::MatchTextChanged()
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->text = matchText->toPlainText().toUtf8().constData();
}
void FileSwitchWidget::UseRegexChanged(int state)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->useRegex = state;
}
void FileSwitchWidget::CheckModificationDateChanged(int state)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->useTime = state;
}
void FileSwitchWidget::CheckFileContentChanged(int state)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->onlyMatchIfChanged = state;
}

View File

@@ -1,31 +1,208 @@
#include "headers/advanced-scene-switcher.hpp"
#include "headers/utility.hpp"
static inline bool SceneGroupValid(SceneGroup *group)
{
if (group) {
return group->name != invalid_scene_group_name;
}
return false;
}
static inline SceneGroup *GetSceneGroupByName(const char *name)
{
if (!switcher) {
return nullptr;
}
for (SceneGroup &sg : switcher->sceneGroups) {
if (sg.name == name) {
return &sg;
}
}
return nullptr;
}
static inline SceneGroup *GetSceneGroupByQString(const QString &name)
{
return GetSceneGroupByName(name.toUtf8().constData());
}
bool SceneSwitcherEntry::initialized()
{
return (usePreviousScene || WeakSourceValid(scene)) && transition;
return (usePreviousScene || WeakSourceValid(scene) ||
SceneGroupValid(group)) &&
(useCurrentTransition || transition);
}
bool SceneSwitcherEntry::valid()
{
return !initialized() ||
((usePreviousScene || WeakSourceValid(scene)) &&
WeakSourceValid(transition));
((usePreviousScene || WeakSourceValid(scene) ||
SceneGroupValid(group)) &&
(useCurrentTransition || WeakSourceValid(transition)));
}
void SceneSwitcherEntry::logMatchScene()
{
std::string sceneName = previous_scene_name;
if (!usePreviousScene) {
sceneName = GetWeakSourceName(scene);
}
blog(LOG_INFO, "match for '%s' - switch to scene '%s'", getType(),
sceneName.c_str());
}
void SceneSwitcherEntry::logMatchSceneGroup()
{
if (group->scenes.empty()) {
blog(LOG_INFO,
"match for '%s' - but no scenes specified in '%s'",
getType(), group->name.c_str());
return;
}
std::string sceneName = GetWeakSourceName(group->getCurrentScene());
blog(LOG_INFO, "match for '%s' - switch to scene '%s' using '%s'",
getType(), sceneName.c_str(), group->name.c_str());
}
void SceneSwitcherEntry::logMatch()
{
const char *sceneName = previous_scene_name;
if (!usePreviousScene) {
obs_source_t *s = obs_weak_source_get_source(scene);
sceneName = obs_source_get_name(s);
obs_source_release(s);
if (targetType == SwitchTargetType::Scene) {
logMatchScene();
} else if (targetType == SwitchTargetType::SceneGroup) {
logMatchSceneGroup();
}
blog(LOG_INFO, "match for '%s' - switch to scene '%s'", getType(),
sceneName);
}
SwitchWidget::SwitchWidget(SceneSwitcherEntry *s, bool usePreviousScene)
OBSWeakSource SceneSwitcherEntry::getScene()
{
if (targetType == SwitchTargetType::Scene) {
if (usePreviousScene && switcher) {
return switcher->previousScene;
}
return scene;
} else if (targetType == SwitchTargetType::SceneGroup) {
return group->getNextScene();
}
return nullptr;
}
void SceneSwitcherEntry::save(obs_data_t *obj, const char *targetTypeSaveName,
const char *targetSaveName,
const char *transitionSaveName)
{
obs_data_set_int(obj, targetTypeSaveName, static_cast<int>(targetType));
std::string targetName = "";
if (targetType == SwitchTargetType::Scene) {
if (usePreviousScene) {
targetName = previous_scene_name;
} else {
targetName = GetWeakSourceName(scene);
}
} else if (targetType == SwitchTargetType::SceneGroup) {
targetName = group->name.c_str();
}
obs_data_set_string(obj, targetSaveName, targetName.c_str());
std::string transitionName = current_transition_name;
if (!useCurrentTransition) {
transitionName = GetWeakSourceName(transition);
}
obs_data_set_string(obj, transitionSaveName, transitionName.c_str());
}
void SceneSwitcherEntry::load(obs_data_t *obj, const char *targetTypeLoadName,
const char *targetLoadName,
const char *transitionLoadName)
{
targetType = static_cast<SwitchTargetType>(
obs_data_get_int(obj, targetTypeLoadName));
const char *targetName = obs_data_get_string(obj, targetLoadName);
if (targetType == SwitchTargetType::Scene) {
usePreviousScene = strcmp(targetName, previous_scene_name) == 0;
if (!usePreviousScene) {
scene = GetWeakSourceByName(targetName);
}
} else if (targetType == SwitchTargetType::SceneGroup) {
group = GetSceneGroupByName(targetName);
}
usePreviousScene = strcmp(targetName, previous_scene_name) == 0;
const char *transitionName =
obs_data_get_string(obj, transitionLoadName);
transition = GetWeakTransitionByName(transitionName);
useCurrentTransition =
strcmp(transitionName, current_transition_name) == 0;
}
void SwitchWidget::SceneGroupAdd(const QString &name)
{
if (!scenes) {
return;
}
scenes->addItem(name);
}
void SwitchWidget::SceneGroupRemove(const QString &name)
{
if (!scenes) {
return;
}
int idx = scenes->findText(name);
if (idx == -1) {
return;
}
scenes->removeItem(idx);
if (switchData && switchData->group == GetSceneGroupByQString(name)) {
std::lock_guard<std::mutex> lock(switcher->m);
switchData->targetType = SwitchTargetType::Scene;
switchData->scene = nullptr;
}
scenes->setCurrentIndex(0);
}
void SwitchWidget::SceneGroupRename(const QString &oldName,
const QString &newName)
{
if (!scenes) {
return;
}
bool renameSelected = scenes->currentText() == oldName;
int idx = scenes->findText(oldName);
if (idx == -1) {
return;
}
scenes->removeItem(idx);
scenes->insertItem(idx, newName);
if (renameSelected) {
scenes->setCurrentIndex(scenes->findText(newName));
}
}
SwitchWidget::SwitchWidget(QWidget *parent, SceneSwitcherEntry *s,
bool usePreviousScene, bool addSceneGroup,
bool addCurrentTransition)
{
scenes = new QComboBox();
transitions = new QComboBox();
@@ -42,21 +219,22 @@ SwitchWidget::SwitchWidget(SceneSwitcherEntry *s, bool usePreviousScene)
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(TransitionChanged(const QString &)));
AdvSceneSwitcher::populateSceneSelection(scenes, usePreviousScene);
AdvSceneSwitcher::populateTransitionSelection(transitions);
QWidget::connect(parent, SIGNAL(SceneGroupAdded(const QString &)), this,
SLOT(SceneGroupAdd(const QString &)));
QWidget::connect(parent, SIGNAL(SceneGroupRemoved(const QString &)),
this, SLOT(SceneGroupRemove(const QString &)));
QWidget::connect(
parent,
SIGNAL(SceneGroupRenamed(const QString &, const QString &)),
this, SLOT(SceneGroupRename(const QString &, const QString &)));
if (s) {
if (s->usePreviousScene)
scenes->setCurrentText(obs_module_text(
"AdvSceneSwitcher.selectPreviousScene"));
else
scenes->setCurrentText(
GetWeakSourceName(s->scene).c_str());
transitions->setCurrentText(
GetWeakSourceName(s->transition).c_str());
}
AdvSceneSwitcher::populateSceneSelection(scenes, usePreviousScene,
addSceneGroup);
AdvSceneSwitcher::populateTransitionSelection(transitions,
addCurrentTransition);
switchData = s;
showSwitchData();
}
SceneSwitcherEntry *SwitchWidget::getSwitchData()
@@ -69,6 +247,34 @@ void SwitchWidget::setSwitchData(SceneSwitcherEntry *s)
switchData = s;
}
void SwitchWidget::showSwitchData()
{
if (!switchData) {
return;
}
transitions->setCurrentText(
GetWeakSourceName(switchData->transition).c_str());
if (switchData->useCurrentTransition) {
transitions->setCurrentText(
obs_module_text("AdvSceneSwitcher.currentTransition"));
}
if (switchData->usePreviousScene) {
scenes->setCurrentText(obs_module_text(
"AdvSceneSwitcher.selectPreviousScene"));
return;
}
scenes->setCurrentText(GetWeakSourceName(switchData->scene).c_str());
if (switchData->group &&
switchData->targetType == SwitchTargetType::SceneGroup) {
scenes->setCurrentText(
QString::fromStdString(switchData->group->name));
}
}
void SwitchWidget::swapSwitchData(SwitchWidget *s1, SwitchWidget *s2)
{
SceneSwitcherEntry *t = s1->getSwitchData();
@@ -84,19 +290,34 @@ bool isPreviousScene(const QString &text)
void SwitchWidget::SceneChanged(const QString &text)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->usePreviousScene = isPreviousScene(text);
if (switchData->usePreviousScene)
if (switchData->usePreviousScene) {
switchData->targetType = SwitchTargetType::Scene;
return;
}
switchData->scene = GetWeakSourceByQString(text);
switchData->targetType = SwitchTargetType::Scene;
if (!switchData->scene) {
switchData->group = GetSceneGroupByQString(text);
switchData->targetType = SwitchTargetType::SceneGroup;
}
}
void SwitchWidget::TransitionChanged(const QString &text)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->transition = GetWeakTransitionByQString(text);
switchData->useCurrentTransition = switchData->transition == nullptr;
}

View File

@@ -4,18 +4,19 @@
#include "headers/utility.hpp"
bool IdleData::pause = false;
IdleWidget *idleWidget = nullptr;
void SwitcherData::checkIdleSwitch(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkIdleSwitch(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (!idleData.idleEnable || IdleData::pause)
return;
if (!idleData.idleEnable || IdleData::pause) {
return false;
}
std::string title;
bool ignoreIdle = false;
//lock.unlock();
GetCurrentWindowTitle(title);
//lock.lock();
bool match = false;
for (std::string &window : ignoreIdleWindows) {
if (window == title) {
@@ -39,96 +40,48 @@ void SwitcherData::checkIdleSwitch(bool &match, OBSWeakSource &scene,
}
if (!ignoreIdle && secondsSinceLastInput() > idleData.time) {
if (idleData.alreadySwitched)
return;
scene = (idleData.usePreviousScene) ? previousScene
: idleData.scene;
if (idleData.alreadySwitched) {
return false;
}
scene = idleData.getScene();
transition = idleData.transition;
match = true;
idleData.alreadySwitched = true;
if (verbose)
if (verbose) {
idleData.logMatch();
} else
}
} else {
idleData.alreadySwitched = false;
}
return match;
}
void AdvSceneSwitcher::on_idleCheckBox_stateChanged(int state)
{
if (loading)
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
if (!state) {
ui->idleScenes->setDisabled(true);
ui->idleSpinBox->setDisabled(true);
ui->idleTransitions->setDisabled(true);
switcher->idleData.idleEnable = false;
idleWidget->setDisabled(true);
} else {
ui->idleScenes->setDisabled(false);
ui->idleSpinBox->setDisabled(false);
ui->idleTransitions->setDisabled(false);
switcher->idleData.idleEnable = true;
UpdateIdleDataTransition(ui->idleTransitions->currentText());
UpdateIdleDataScene(ui->idleScenes->currentText());
idleWidget->setDisabled(false);
}
}
void AdvSceneSwitcher::UpdateIdleDataTransition(const QString &name)
{
obs_weak_source_t *transition = GetWeakTransitionByQString(name);
switcher->idleData.transition = transition;
}
void AdvSceneSwitcher::UpdateIdleDataScene(const QString &name)
{
switcher->idleData.usePreviousScene =
(name ==
obs_module_text("AdvSceneSwitcher.selectPreviousScene"));
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
switcher->idleData.scene = ws;
obs_weak_source_release(ws);
obs_source_release(scene);
}
void AdvSceneSwitcher::on_idleTransitions_currentTextChanged(const QString &text)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
UpdateIdleDataTransition(text);
}
void AdvSceneSwitcher::on_idleScenes_currentTextChanged(const QString &text)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
UpdateIdleDataScene(text);
}
void AdvSceneSwitcher::on_idleSpinBox_valueChanged(int i)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
switcher->idleData.time = i;
}
void AdvSceneSwitcher::on_ignoreIdleWindows_currentRowChanged(int idx)
{
if (loading)
if (loading) {
return;
if (idx == -1)
}
if (idx == -1) {
return;
}
QListWidgetItem *item = ui->ignoreIdleWindows->item(idx);
@@ -147,8 +100,9 @@ void AdvSceneSwitcher::on_ignoreIdleAdd_clicked()
{
QString windowName = ui->ignoreIdleWindowsWindows->currentText();
if (windowName.isEmpty())
if (windowName.isEmpty()) {
return;
}
QVariant v = QVariant::fromValue(windowName);
@@ -170,8 +124,9 @@ void AdvSceneSwitcher::on_ignoreIdleAdd_clicked()
void AdvSceneSwitcher::on_ignoreIdleRemove_clicked()
{
QListWidgetItem *item = ui->ignoreIdleWindows->currentItem();
if (!item)
if (!item) {
return;
}
QString windowName = item->data(Qt::UserRole).toString();
@@ -213,7 +168,7 @@ int AdvSceneSwitcher::IgnoreIdleWindowsFindByData(const QString &window)
void SwitcherData::saveIdleSwitches(obs_data_t *obj)
{
obs_data_array_t *ignoreIdleWindowsArray = obs_data_array_create();
for (std::string &window : switcher->ignoreIdleWindows) {
for (std::string &window : ignoreIdleWindows) {
obs_data_t *array_obj = obs_data_create();
obs_data_set_string(array_obj, "window", window.c_str());
obs_data_array_push_back(ignoreIdleWindowsArray, array_obj);
@@ -222,22 +177,12 @@ void SwitcherData::saveIdleSwitches(obs_data_t *obj)
obs_data_set_array(obj, "ignoreIdleWindows", ignoreIdleWindowsArray);
obs_data_array_release(ignoreIdleWindowsArray);
std::string idleSceneName = GetWeakSourceName(switcher->idleData.scene);
std::string idleTransitionName =
GetWeakSourceName(switcher->idleData.transition);
obs_data_set_bool(obj, "idleEnable", switcher->idleData.idleEnable);
obs_data_set_string(obj, "idleSceneName",
switcher->idleData.usePreviousScene
? previous_scene_name
: idleSceneName.c_str());
obs_data_set_string(obj, "idleTransitionName",
idleTransitionName.c_str());
obs_data_set_int(obj, "idleTime", switcher->idleData.time);
idleData.save(obj);
}
void SwitcherData::loadIdleSwitches(obs_data_t *obj)
{
switcher->ignoreIdleWindows.clear();
ignoreIdleWindows.clear();
obs_data_array_t *ignoreIdleWindowsArray =
obs_data_get_array(obj, "ignoreIdleWindows");
@@ -249,30 +194,20 @@ void SwitcherData::loadIdleSwitches(obs_data_t *obj)
const char *window = obs_data_get_string(array_obj, "window");
switcher->ignoreIdleWindows.emplace_back(window);
ignoreIdleWindows.emplace_back(window);
obs_data_release(array_obj);
}
obs_data_array_release(ignoreIdleWindowsArray);
std::string idleSceneName = obs_data_get_string(obj, "idleSceneName");
std::string idleTransitionName =
obs_data_get_string(obj, "idleTransitionName");
switcher->idleData.scene = GetWeakSourceByName(idleSceneName.c_str());
switcher->idleData.transition =
GetWeakTransitionByName(idleTransitionName.c_str());
obs_data_set_default_bool(obj, "idleEnable", false);
switcher->idleData.idleEnable = obs_data_get_bool(obj, "idleEnable");
obs_data_set_default_int(obj, "idleTime", default_idle_time);
switcher->idleData.time = obs_data_get_int(obj, "idleTime");
switcher->idleData.usePreviousScene =
(idleSceneName == previous_scene_name);
idleData.load(obj);
}
void AdvSceneSwitcher::setupIdleTab()
{
populateSceneSelection(ui->idleScenes, true);
populateTransitionSelection(ui->idleTransitions);
populateWindowSelection(ui->ignoreIdleWindowsWindows);
for (auto &window : switcher->ignoreIdleWindows) {
@@ -283,25 +218,71 @@ void AdvSceneSwitcher::setupIdleTab()
item->setData(Qt::UserRole, text);
}
idleWidget = new IdleWidget(this, &switcher->idleData);
ui->idleWidgetLayout->addWidget(idleWidget);
ui->idleCheckBox->setChecked(switcher->idleData.idleEnable);
if (switcher->idleData.usePreviousScene) {
ui->idleScenes->setCurrentText(obs_module_text(
"AdvSceneSwitcher.selectPreviousScene"));
} else {
ui->idleScenes->setCurrentText(
GetWeakSourceName(switcher->idleData.scene).c_str());
}
ui->idleTransitions->setCurrentText(
GetWeakSourceName(switcher->idleData.transition).c_str());
ui->idleSpinBox->setValue(switcher->idleData.time);
if (ui->idleCheckBox->checkState()) {
ui->idleScenes->setDisabled(false);
ui->idleSpinBox->setDisabled(false);
ui->idleTransitions->setDisabled(false);
idleWidget->setDisabled(false);
} else {
ui->idleScenes->setDisabled(true);
ui->idleSpinBox->setDisabled(true);
ui->idleTransitions->setDisabled(true);
idleWidget->setDisabled(true);
}
}
void IdleData::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj, "idleTargetType", "idleSceneName",
"idleTransitionName");
obs_data_set_bool(obj, "idleEnable", idleEnable);
obs_data_set_int(obj, "idleTime", time);
}
void IdleData::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj, "idleTargetType", "idleSceneName",
"idleTransitionName");
idleEnable = obs_data_get_bool(obj, "idleEnable");
time = obs_data_get_int(obj, "idleTime");
}
IdleWidget::IdleWidget(QWidget *parent, IdleData *s)
: SwitchWidget(parent, s, true, true)
{
duration = new QSpinBox();
duration->setMinimum(0);
duration->setMaximum(1000000);
duration->setSuffix("s");
QWidget::connect(duration, SIGNAL(valueChanged(int)), this,
SLOT(DurationChanged(int)));
if (s) {
duration->setValue(s->time);
}
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{duration}}", duration},
{"{{scenes}}", scenes},
{"{{transitions}}", transitions}};
placeWidgets(obs_module_text("AdvSceneSwitcher.idleTab.idleswitch"),
mainLayout, widgetPlaceholders);
setLayout(mainLayout);
switchData = s;
loading = false;
}
void IdleWidget::DurationChanged(int dur)
{
if (loading) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->idleData.time = dur;
}

View File

@@ -13,15 +13,19 @@ void AdvSceneSwitcher::on_mediaAdd_clicked()
switcher->mediaSwitches.emplace_back();
listAddClicked(ui->mediaSwitches,
new MediaSwitchWidget(&switcher->mediaSwitches.back()),
new MediaSwitchWidget(this,
&switcher->mediaSwitches.back()),
ui->mediaAdd, &addPulse);
ui->mediaHelp->setVisible(false);
}
void AdvSceneSwitcher::on_mediaRemove_clicked()
{
QListWidgetItem *item = ui->mediaSwitches->currentItem();
if (!item)
if (!item) {
return;
}
{
std::lock_guard<std::mutex> lock(switcher->m);
@@ -36,8 +40,9 @@ void AdvSceneSwitcher::on_mediaRemove_clicked()
void AdvSceneSwitcher::on_mediaUp_clicked()
{
int index = ui->mediaSwitches->currentRow();
if (!listMoveUp(ui->mediaSwitches))
if (!listMoveUp(ui->mediaSwitches)) {
return;
}
MediaSwitchWidget *s1 =
(MediaSwitchWidget *)ui->mediaSwitches->itemWidget(
@@ -57,8 +62,9 @@ void AdvSceneSwitcher::on_mediaDown_clicked()
{
int index = ui->mediaSwitches->currentRow();
if (!listMoveDown(ui->mediaSwitches))
if (!listMoveDown(ui->mediaSwitches)) {
return;
}
MediaSwitchWidget *s1 =
(MediaSwitchWidget *)ui->mediaSwitches->itemWidget(
@@ -74,15 +80,18 @@ void AdvSceneSwitcher::on_mediaDown_clicked()
switcher->mediaSwitches[index + 1]);
}
void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
bool SwitcherData::checkMediaSwitch(OBSWeakSource &scene,
OBSWeakSource &transition)
{
if (MediaSwitch::pause)
return;
if (MediaSwitch::pause) {
return false;
}
bool match = false;
for (MediaSwitch &mediaSwitch : mediaSwitches) {
if (!mediaSwitch.initialized())
if (!mediaSwitch.initialized()) {
continue;
}
obs_source_t *source =
obs_weak_source_get_source(mediaSwitch.source);
@@ -135,8 +144,9 @@ void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
(duration - time <= interval * 2);
// reset
if (ended)
if (ended) {
mediaSwitch.playedToEnd = false;
}
// reset for next check
mediaSwitch.stopped = false;
@@ -173,55 +183,31 @@ void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
if (matched && !mediaSwitch.matched) {
match = true;
scene = (mediaSwitch.usePreviousScene)
? previousScene
: mediaSwitch.scene;
scene = mediaSwitch.getScene();
transition = mediaSwitch.transition;
if (verbose)
if (verbose) {
mediaSwitch.logMatch();
}
}
mediaSwitch.matched = matched;
if (match)
if (match) {
break;
}
}
return match;
}
void SwitcherData::saveMediaSwitches(obs_data_t *obj)
{
obs_data_array_t *mediaArray = obs_data_array_create();
for (MediaSwitch &s : switcher->mediaSwitches) {
for (MediaSwitch &s : mediaSwitches) {
obs_data_t *array_obj = obs_data_create();
obs_source_t *source = obs_weak_source_get_source(s.source);
obs_source_t *sceneSource = obs_weak_source_get_source(s.scene);
obs_source_t *transition =
obs_weak_source_get_source(s.transition);
if ((s.usePreviousScene || sceneSource) && source &&
transition) {
const char *sourceName = obs_source_get_name(source);
const char *sceneName =
obs_source_get_name(sceneSource);
const char *transitionName =
obs_source_get_name(transition);
obs_data_set_string(array_obj, "source", sourceName);
obs_data_set_string(array_obj, "scene",
s.usePreviousScene
? previous_scene_name
: sceneName);
obs_data_set_string(array_obj, "transition",
transitionName);
obs_data_set_int(array_obj, "state", s.state);
obs_data_set_int(array_obj, "restriction",
s.restriction);
obs_data_set_int(array_obj, "time", s.time);
obs_data_array_push_back(mediaArray, array_obj);
}
obs_source_release(source);
obs_source_release(sceneSource);
obs_source_release(transition);
s.save(array_obj);
obs_data_array_push_back(mediaArray, array_obj);
obs_data_release(array_obj);
}
@@ -232,27 +218,14 @@ void SwitcherData::saveMediaSwitches(obs_data_t *obj)
void SwitcherData::loadMediaSwitches(obs_data_t *obj)
{
obs_data_array_t *mediaArray = obs_data_get_array(obj, "mediaSwitches");
switcher->mediaSwitches.clear();
mediaSwitches.clear();
size_t count = obs_data_array_count(mediaArray);
for (size_t i = 0; i < count; i++) {
obs_data_t *array_obj = obs_data_array_item(mediaArray, i);
const char *source = obs_data_get_string(array_obj, "source");
const char *scene = obs_data_get_string(array_obj, "scene");
const char *transition =
obs_data_get_string(array_obj, "transition");
obs_media_state state =
(obs_media_state)obs_data_get_int(array_obj, "state");
time_restriction restriction =
(time_restriction)obs_data_get_int(array_obj,
"restriction");
uint64_t time = obs_data_get_int(array_obj, "time");
switcher->mediaSwitches.emplace_back(
GetWeakSourceByName(scene), GetWeakSourceByName(source),
GetWeakTransitionByName(transition), state, restriction,
time, (strcmp(scene, previous_scene_name) == 0));
mediaSwitches.emplace_back();
mediaSwitches.back().load(array_obj);
obs_data_release(array_obj);
}
@@ -265,13 +238,17 @@ void AdvSceneSwitcher::setupMediaTab()
QListWidgetItem *item;
item = new QListWidgetItem(ui->mediaSwitches);
ui->mediaSwitches->addItem(item);
MediaSwitchWidget *sw = new MediaSwitchWidget(&s);
MediaSwitchWidget *sw = new MediaSwitchWidget(this, &s);
item->setSizeHint(sw->minimumSizeHint());
ui->mediaSwitches->setItemWidget(item, sw);
}
if (switcher->mediaSwitches.size() == 0)
if (switcher->mediaSwitches.size() == 0) {
addPulse = PulseWidget(ui->mediaAdd, QColor(Qt::green));
ui->mediaHelp->setVisible(true);
} else {
ui->mediaHelp->setVisible(false);
}
}
bool MediaSwitch::initialized()
@@ -285,6 +262,36 @@ bool MediaSwitch::valid()
(SceneSwitcherEntry::valid() && WeakSourceValid(source));
}
void MediaSwitch::save(obs_data_t *obj)
{
SceneSwitcherEntry::save(obj);
obs_data_set_string(obj, "source", GetWeakSourceName(source).c_str());
obs_data_set_int(obj, "state", state);
obs_data_set_int(obj, "restriction", restriction);
obs_data_set_int(obj, "time", time);
}
void MediaSwitch::load(obs_data_t *obj)
{
SceneSwitcherEntry::load(obj);
const char *sourceName = obs_data_get_string(obj, "source");
source = GetWeakSourceByName(sourceName);
state = (obs_media_state)obs_data_get_int(obj, "state");
restriction = (time_restriction)obs_data_get_int(obj, "restriction");
time = obs_data_get_int(obj, "time");
anyState = state == media_any_idx;
obs_source_t *mediasource = obs_weak_source_get_source(source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_connect(sh, "media_stopped", MediaStopped, this);
signal_handler_connect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
}
void MediaSwitch::clearSignalHandler()
{
obs_source_t *mediasource = obs_weak_source_get_source(source);
@@ -317,28 +324,9 @@ void MediaSwitch::MediaEnded(void *data, calldata_t *)
media->ended = true;
}
inline MediaSwitch::MediaSwitch(OBSWeakSource scene_, OBSWeakSource source_,
OBSWeakSource transition_,
obs_media_state state_,
time_restriction restriction_, uint64_t time_,
bool usePreviousScene_)
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
source(source_),
state(state_),
restriction(restriction_),
time(time_)
{
anyState = state == media_any_idx;
obs_source_t *mediasource = obs_weak_source_get_source(source);
signal_handler_t *sh = obs_source_get_signal_handler(mediasource);
signal_handler_connect(sh, "media_stopped", MediaStopped, this);
signal_handler_connect(sh, "media_ended", MediaEnded, this);
obs_source_release(mediasource);
}
MediaSwitch::MediaSwitch(const MediaSwitch &other)
: SceneSwitcherEntry(other.scene, other.transition,
other.usePreviousScene),
: SceneSwitcherEntry(other.targetType, other.group, other.scene,
other.transition, other.usePreviousScene),
source(other.source),
state(other.state),
restriction(other.restriction),
@@ -353,8 +341,8 @@ MediaSwitch::MediaSwitch(const MediaSwitch &other)
}
MediaSwitch::MediaSwitch(MediaSwitch &&other)
: SceneSwitcherEntry(other.scene, other.transition,
other.usePreviousScene),
: SceneSwitcherEntry(other.targetType, other.group, other.scene,
other.transition, other.usePreviousScene),
source(other.source),
state(other.state),
anyState(other.anyState),
@@ -398,6 +386,8 @@ MediaSwitch &MediaSwitch::operator=(MediaSwitch &&other) noexcept
void swap(MediaSwitch &first, MediaSwitch &second)
{
std::swap(first.targetType, second.targetType);
std::swap(first.group, second.group);
std::swap(first.scene, second.scene);
std::swap(first.transition, second.transition);
std::swap(first.usePreviousScene, second.usePreviousScene);
@@ -410,7 +400,7 @@ void swap(MediaSwitch &first, MediaSwitch &second)
second.resetSignalHandler();
}
void populateMediaStates(QComboBox *list)
static void populateMediaStates(QComboBox *list)
{
list->addItem(obs_module_text("AdvSceneSwitcher.mediaTab.states.none"));
list->addItem(
@@ -432,7 +422,7 @@ void populateMediaStates(QComboBox *list)
list->addItem(obs_module_text("AdvSceneSwitcher.mediaTab.states.any"));
}
void populateTimeRestrictions(QComboBox *list)
static void populateTimeRestrictions(QComboBox *list)
{
list->addItem(obs_module_text(
"AdvSceneSwitcher.mediaTab.timeRestriction.none"));
@@ -446,7 +436,8 @@ void populateTimeRestrictions(QComboBox *list)
"AdvSceneSwitcher.mediaTab.timeRestriction.remainLonger"));
}
MediaSwitchWidget::MediaSwitchWidget(MediaSwitch *s) : SwitchWidget(s)
MediaSwitchWidget::MediaSwitchWidget(QWidget *parent, MediaSwitch *s)
: SwitchWidget(parent, s, true, true)
{
mediaSources = new QComboBox();
states = new QComboBox();
@@ -477,8 +468,9 @@ MediaSwitchWidget::MediaSwitchWidget(MediaSwitch *s) : SwitchWidget(s)
states->setCurrentIndex(s->state);
timeRestrictions->setCurrentIndex(s->restriction);
time->setValue(s->time);
if (s->restriction == TIME_RESTRICTION_NONE)
if (s->restriction == TIME_RESTRICTION_NONE) {
time->setDisabled(true);
}
}
QHBoxLayout *mainLayout = new QHBoxLayout;
@@ -520,8 +512,10 @@ void MediaSwitchWidget::swapSwitchData(MediaSwitchWidget *s1,
void MediaSwitchWidget::SourceChanged(const QString &text)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->clearSignalHandler();
switchData->source = GetWeakSourceByQString(text);
@@ -530,8 +524,10 @@ void MediaSwitchWidget::SourceChanged(const QString &text)
void MediaSwitchWidget::StateChanged(int index)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->state = (obs_media_state)index;
switchData->anyState = switchData->state == media_any_idx;
@@ -539,13 +535,15 @@ void MediaSwitchWidget::StateChanged(int index)
void MediaSwitchWidget::TimeRestrictionChanged(int index)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
if ((time_restriction)index == TIME_RESTRICTION_NONE)
if ((time_restriction)index == TIME_RESTRICTION_NONE) {
time->setDisabled(true);
else
} else {
time->setDisabled(false);
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->restriction = (time_restriction)index;
@@ -553,8 +551,10 @@ void MediaSwitchWidget::TimeRestrictionChanged(int index)
void MediaSwitchWidget::TimeChanged(int time)
{
if (loading || !switchData)
if (loading || !switchData) {
return;
}
std::lock_guard<std::mutex> lock(switcher->m);
switchData->time = time;
}

Some files were not shown because too many files have changed in this diff Show More