mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-07 09:05:57 -05:00
Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d023ee385 | ||
|
|
3fd3801e56 | ||
|
|
3ec1e99f4b | ||
|
|
21a788b48b | ||
|
|
a5c8d776f3 | ||
|
|
95261ce9bb | ||
|
|
255d10e603 | ||
|
|
ab3e93ab84 | ||
|
|
3b5f88c14f | ||
|
|
2f33b6bdc3 | ||
|
|
3c1e240722 | ||
|
|
91831a1075 | ||
|
|
ccc824abc1 | ||
|
|
6f39d4648b | ||
|
|
74cb400426 | ||
|
|
910b1dde99 | ||
|
|
e462d7f420 | ||
|
|
0cdd8bf1d0 | ||
|
|
f8ad8c31be | ||
|
|
93c889c215 | ||
|
|
f8b505fa4e | ||
|
|
1516263d2a | ||
|
|
79f5ec340d | ||
|
|
cd54cc17c0 | ||
|
|
098159dc0f | ||
|
|
a4418996f4 | ||
|
|
340cb559ee | ||
|
|
eeefd8279f | ||
|
|
e62dc91cd7 | ||
|
|
536041abd2 | ||
|
|
d3ab9e01c5 | ||
|
|
2113025877 | ||
|
|
6aaffeb5a4 | ||
|
|
2a92df4f3c | ||
|
|
560044bbbf | ||
|
|
4bd8cdf5a0 | ||
|
|
c17cbb66d9 | ||
|
|
8d23dd46b0 | ||
|
|
bf70bd7c60 | ||
|
|
1a144d84f5 | ||
|
|
6810ba71e8 | ||
|
|
bbe6a30506 | ||
|
|
08c668f90a | ||
|
|
3151a7542f | ||
|
|
7bfde0a39b | ||
|
|
7347be370e | ||
|
|
66d847c047 | ||
|
|
c9f1f9624b | ||
|
|
8e4a8b7e9d | ||
|
|
e693794549 | ||
|
|
7a924438bc | ||
|
|
7458e9f2d5 | ||
|
|
da2e11e35e | ||
|
|
9f7ca3e4c7 | ||
|
|
2f77d99161 | ||
|
|
acd2e2863a | ||
|
|
513fe0728c | ||
|
|
cba39633aa | ||
|
|
c6a26d862f | ||
|
|
9386109168 | ||
|
|
4b86849356 | ||
|
|
8fd263f44a | ||
|
|
5590e97f4f | ||
|
|
98c3131017 | ||
|
|
f03fca85aa | ||
|
|
7fef29dafb | ||
|
|
9f03264672 | ||
|
|
5082f5944e | ||
|
|
b981a446b6 | ||
|
|
5ab8199e03 | ||
|
|
e6a3f98ab7 | ||
|
|
5e60cefd1c | ||
|
|
fabb7406bd | ||
|
|
cfb0a44b1f | ||
|
|
78ed7415f5 | ||
|
|
d6380b865e | ||
|
|
55d8303ecf | ||
|
|
23201100fa | ||
|
|
3959e41e88 | ||
|
|
f0cf5a5c19 | ||
|
|
87da123c19 | ||
|
|
2a0e9e9d9a | ||
|
|
a7a8adb91b | ||
|
|
e61905d02f | ||
|
|
f00c244bfa | ||
|
|
463b54f1fb | ||
|
|
70894f9302 | ||
|
|
de5b6f8eb4 | ||
|
|
be83232caa | ||
|
|
e4b640903d | ||
|
|
a4de8c0c59 | ||
|
|
ac051a42a8 | ||
|
|
e33e93fd18 | ||
|
|
d5052c94ca | ||
|
|
f0aa76517a | ||
|
|
a2543f1b85 | ||
|
|
5f87a61177 | ||
|
|
451bb6518c | ||
|
|
318502d8d0 | ||
|
|
e9b1ef58ba | ||
|
|
26c24d4d53 | ||
|
|
3654f39247 | ||
|
|
b45b38cf6a |
107
.clang-format
Normal file
107
.clang-format
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# please use clang-format version 8 or later
|
||||||
|
|
||||||
|
Standard: Cpp11
|
||||||
|
AccessModifierOffset: -8
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
#AllowAllArgumentsOnNextLine: false # requires clang-format 9
|
||||||
|
#AllowAllConstructorInitializersOnNextLine: false # requires clang-format 9
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
#AllowShortLambdasOnASingleLine: Inline # requires clang-format 9
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: false
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakStringLiterals: false # apparently unpredictable
|
||||||
|
ColumnLimit: 80
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 8
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
FixNamespaceComments: false
|
||||||
|
ForEachMacros:
|
||||||
|
- 'json_object_foreach'
|
||||||
|
- 'json_object_foreach_safe'
|
||||||
|
- 'json_array_foreach'
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 8
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
#ObjCBinPackProtocolList: Auto # requires clang-format 7
|
||||||
|
ObjCBlockIndentWidth: 8
|
||||||
|
ObjCSpaceAfterProperty: true
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
|
||||||
|
PenaltyBreakAssignment: 10
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 30
|
||||||
|
PenaltyBreakComment: 10
|
||||||
|
PenaltyBreakFirstLessLess: 0
|
||||||
|
PenaltyBreakString: 10
|
||||||
|
PenaltyExcessCharacter: 100
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: false
|
||||||
|
SortIncludes: false
|
||||||
|
SortUsingDeclarations: false
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
#SpaceAfterLogicalNot: false # requires clang-format 9
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
#SpaceBeforeCtorInitializerColon: true # requires clang-format 7
|
||||||
|
#SpaceBeforeInheritanceColon: true # requires clang-format 7
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
#SpaceBeforeRangeBasedForLoopColon: true # requires clang-format 7
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
#StatementMacros: # requires clang-format 8
|
||||||
|
# - 'Q_OBJECT'
|
||||||
|
TabWidth: 8
|
||||||
|
#TypenameMacros: # requires clang-format 9
|
||||||
|
# - 'DARRAY'
|
||||||
|
UseTab: ForContinuationAndIndentation
|
||||||
|
---
|
||||||
|
Language: ObjC
|
||||||
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
runs-on: [macos-latest]
|
runs-on: [macos-latest]
|
||||||
env:
|
env:
|
||||||
QT_VERSION: 5.14.1
|
QT_VERSION: 5.14.1
|
||||||
OSX_DEPS_VERSION: '2020-04-07'
|
MACOS_DEPS_VERSION: '2020-08-30'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -35,20 +35,29 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cd UI/frontend-plugins/${{ env.PLUGIN_NAME }}/CI/macos
|
cd UI/frontend-plugins/${{ env.PLUGIN_NAME }}/CI/macos
|
||||||
|
brew update
|
||||||
brew bundle
|
brew bundle
|
||||||
cd -
|
cd -
|
||||||
- name: 'Install prerequisite: Pre-built dependencies'
|
- name: 'Install prerequisite: Pre-built dependencies'
|
||||||
|
if: steps.deps-cache.outputs.cache-hit != 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
curl -L -O https://github.com/obsproject/obs-deps/releases/download/${{ env.OSX_DEPS_VERSION }}/osx-deps-${{ env.OSX_DEPS_VERSION }}.tar.gz
|
curl -L -O https://github.com/obsproject/obs-deps/releases/download/${{ env.MACOS_DEPS_VERSION }}/macos-deps-${{ env.MACOS_DEPS_VERSION }}.tar.gz
|
||||||
tar -xf ./osx-deps-${{ env.OSX_DEPS_VERSION }}.tar.gz -C "/tmp"
|
tar -xf ./macos-deps-${{ env.MACOS_DEPS_VERSION }}.tar.gz -C "/tmp"
|
||||||
|
- name: 'Install prerequisite: Pre-built dependency Qt'
|
||||||
|
if: steps.deps-qt-cache.outputs.cache-hit != 'true'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
curl -L -O https://github.com/obsproject/obs-deps/releases/download/${{ env.MACOS_DEPS_VERSION }}/macos-qt-${{ env.QT_VERSION }}-${{ env.MACOS_DEPS_VERSION }}.tar.gz
|
||||||
|
tar -xf ./macos-qt-${{ env.QT_VERSION }}-${{ env.MACOS_DEPS_VERSION }}.tar.gz -C "/tmp"
|
||||||
|
xattr -r -d com.apple.quarantine /tmp/obsdeps
|
||||||
- name: Configure
|
- name: Configure
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo "add_subdirectory(${{ env.PLUGIN_NAME }})" >> UI/frontend-plugins/CMakeLists.txt
|
echo "add_subdirectory(${{ env.PLUGIN_NAME }})" >> UI/frontend-plugins/CMakeLists.txt
|
||||||
mkdir ./build
|
mkdir ./build
|
||||||
cd ./build
|
cd ./build
|
||||||
cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DDepsPath="/tmp/obsdeps" -DQTDIR="/usr/local/Cellar/qt/${{ env.QT_VERSION }}" ..
|
cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DDISABLE_PYTHON=ON -DDepsPath="/tmp/obsdeps" -DQTDIR="/tmp/obsdeps" ..
|
||||||
cd -
|
cd -
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -70,9 +79,9 @@ jobs:
|
|||||||
cd UI/frontend-plugins/${{ env.PLUGIN_NAME }}
|
cd UI/frontend-plugins/${{ env.PLUGIN_NAME }}
|
||||||
install_name_tool -change @rpath/libobs-frontend-api.dylib @executable_path/../Frameworks/libobs-frontend-api.dylib ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
install_name_tool -change @rpath/libobs-frontend-api.dylib @executable_path/../Frameworks/libobs-frontend-api.dylib ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
||||||
install_name_tool -change @rpath/libobs.0.dylib @executable_path/../Frameworks/libobs.0.dylib ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
install_name_tool -change @rpath/libobs.0.dylib @executable_path/../Frameworks/libobs.0.dylib ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
||||||
install_name_tool -change /usr/local/opt/qt5/lib/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
install_name_tool -change /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
||||||
install_name_tool -change /usr/local/opt/qt5/lib/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
install_name_tool -change /usr/local/opt/qt/lib/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
||||||
install_name_tool -change /usr/local/opt/qt5/lib/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
install_name_tool -change /usr/local/opt/qt/lib/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore ../../../build/UI/frontend-plugins/SceneSwitcher/advanced-scene-switcher.so
|
||||||
FILE_DATE=$(date +%Y-%m-%d)
|
FILE_DATE=$(date +%Y-%m-%d)
|
||||||
FILE_NAME=${{ env.PLUGIN_NAME }}-$FILE_DATE-${{ github.sha }}-macos.pkg
|
FILE_NAME=${{ env.PLUGIN_NAME }}-$FILE_DATE-${{ github.sha }}-macos.pkg
|
||||||
echo "::set-env name=FILE_NAME::${FILE_NAME}"
|
echo "::set-env name=FILE_NAME::${FILE_NAME}"
|
||||||
|
|||||||
@@ -2,5 +2,4 @@ brew "jack"
|
|||||||
brew "speexdsp"
|
brew "speexdsp"
|
||||||
brew "cmake"
|
brew "cmake"
|
||||||
brew "freetype"
|
brew "freetype"
|
||||||
brew "fdk-aac"
|
brew "fdk-aac"
|
||||||
brew "https://gist.githubusercontent.com/DDRBoxman/9c7a2b08933166f4b61ed9a44b242609/raw/ef4de6c587c6bd7f50210eccd5bd51ff08e6de13/qt.rb"
|
|
||||||
@@ -13,6 +13,7 @@ if(BUILD_OUT_OF_TREE)
|
|||||||
find_package(LibObs REQUIRED)
|
find_package(LibObs REQUIRED)
|
||||||
find_package(Qt5Core REQUIRED)
|
find_package(Qt5Core REQUIRED)
|
||||||
find_package(Qt5Widgets REQUIRED)
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
find_package(Libcurl REQUIRED)
|
||||||
find_path(LIBOBS_FRONTEND_INCLUDE_DIR HINTS ${LIBOBS_INCLUDE_DIRS})
|
find_path(LIBOBS_FRONTEND_INCLUDE_DIR HINTS ${LIBOBS_INCLUDE_DIRS})
|
||||||
find_file(LIBOBS_FRONTEND_API_LIB NAMES libobs-frontend-api.* HINTS ${LIBOBS_LIB} )
|
find_file(LIBOBS_FRONTEND_API_LIB NAMES libobs-frontend-api.* HINTS ${LIBOBS_LIB} )
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ if(BUILD_OUT_OF_TREE)
|
|||||||
src/headers/advanced-scene-switcher.hpp
|
src/headers/advanced-scene-switcher.hpp
|
||||||
src/headers/switcher-data-structs.hpp
|
src/headers/switcher-data-structs.hpp
|
||||||
src/headers/utility.hpp
|
src/headers/utility.hpp
|
||||||
|
src/headers/curl-helper.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(advanced-scene-switcher_SOURCES
|
set(advanced-scene-switcher_SOURCES
|
||||||
@@ -54,6 +56,7 @@ if(BUILD_OUT_OF_TREE)
|
|||||||
src/pause-switch.cpp
|
src/pause-switch.cpp
|
||||||
src/random.cpp
|
src/random.cpp
|
||||||
src/time-switch.cpp
|
src/time-switch.cpp
|
||||||
|
src/curl-helper.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(advanced-scene-switcher_UI
|
set(advanced-scene-switcher_UI
|
||||||
@@ -96,7 +99,8 @@ if(BUILD_OUT_OF_TREE)
|
|||||||
"${LIBOBS_INCLUDE_DIRS}"
|
"${LIBOBS_INCLUDE_DIRS}"
|
||||||
"${LIBOBS_FRONTEND_INCLUDE_DIR}"
|
"${LIBOBS_FRONTEND_INCLUDE_DIR}"
|
||||||
${Qt5Core_INCLUDES}
|
${Qt5Core_INCLUDES}
|
||||||
${Qt5Widgets_INCLUDES})
|
${Qt5Widgets_INCLUDES}
|
||||||
|
${LIBCURL_INCLUDE_DIRS})
|
||||||
|
|
||||||
target_link_libraries(advanced-scene-switcher
|
target_link_libraries(advanced-scene-switcher
|
||||||
${advanced-scene-switcher_PLATFORM_LIBS}
|
${advanced-scene-switcher_PLATFORM_LIBS}
|
||||||
@@ -164,6 +168,8 @@ else ()
|
|||||||
src/headers/advanced-scene-switcher.hpp
|
src/headers/advanced-scene-switcher.hpp
|
||||||
src/headers/switcher-data-structs.hpp
|
src/headers/switcher-data-structs.hpp
|
||||||
src/headers/utility.hpp
|
src/headers/utility.hpp
|
||||||
|
src/headers/curl-helper.hpp
|
||||||
|
src/headers/volume-control.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(advanced-scene-switcher_SOURCES
|
set(advanced-scene-switcher_SOURCES
|
||||||
@@ -184,6 +190,9 @@ else ()
|
|||||||
src/pause-switch.cpp
|
src/pause-switch.cpp
|
||||||
src/random.cpp
|
src/random.cpp
|
||||||
src/time-switch.cpp
|
src/time-switch.cpp
|
||||||
|
src/audio-switch.cpp
|
||||||
|
src/curl-helper.cpp
|
||||||
|
src/volume-control.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(advanced-scene-switcher_UI
|
set(advanced-scene-switcher_UI
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
327
src/audio-switch.cpp
Normal file
327
src/audio-switch.cpp
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
#include "headers/volume-control.hpp"
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioSwitches_currentRowChanged(int idx)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QListWidgetItem *item = ui->audioSwitches->item(idx);
|
||||||
|
|
||||||
|
QString audioScenestr = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
for (auto &s : switcher->audioSwitches) {
|
||||||
|
if (audioScenestr.compare(s.audioSwitchStr.c_str()) == 0) {
|
||||||
|
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
||||||
|
QString audioSrouceName =
|
||||||
|
GetWeakSourceName(s.audioSource).c_str();
|
||||||
|
QString transitionName =
|
||||||
|
GetWeakSourceName(s.transition).c_str();
|
||||||
|
ui->audioScenes->setCurrentText(sceneName);
|
||||||
|
ui->audioTransitions->setCurrentText(transitionName);
|
||||||
|
ui->audioSources->setCurrentText(audioSrouceName);
|
||||||
|
ui->audioVolumeThreshold->setValue(s.volumeThreshold);
|
||||||
|
volMeter->GetSlider()->setValue(s.volumeThreshold);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioSources_currentTextChanged(const QString &text)
|
||||||
|
{
|
||||||
|
SetAudioVolumeMeter(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::SetAudioVolumeMeter(const QString &name)
|
||||||
|
{
|
||||||
|
obs_source_t *soruce =
|
||||||
|
obs_get_source_by_name(name.toUtf8().constData());
|
||||||
|
if (!soruce) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volMeter) {
|
||||||
|
ui->audioControlLayout->removeWidget(volMeter);
|
||||||
|
delete volMeter;
|
||||||
|
}
|
||||||
|
|
||||||
|
volMeter = new VolControl(soruce);
|
||||||
|
ui->audioControlLayout->addWidget(volMeter);
|
||||||
|
obs_source_release(soruce);
|
||||||
|
|
||||||
|
QWidget::connect(volMeter->GetSlider(), SIGNAL(valueChanged(int)),
|
||||||
|
ui->audioVolumeThreshold, SLOT(setValue(int)));
|
||||||
|
QWidget::connect(ui->audioVolumeThreshold, SIGNAL(valueChanged(int)),
|
||||||
|
volMeter->GetSlider(), SLOT(setValue(int)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int SceneSwitcher::audioFindByData(const QString &source, const int &volume)
|
||||||
|
{
|
||||||
|
QRegExp rx(MakeAudioSwitchName(QStringLiteral(".*"),
|
||||||
|
QStringLiteral(".*"), source, volume));
|
||||||
|
int count = ui->audioSwitches->count();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
QListWidgetItem *item = ui->audioSwitches->item(i);
|
||||||
|
QString str = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
|
if (rx.exactMatch(str))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioAdd_clicked()
|
||||||
|
{
|
||||||
|
QString sceneName = ui->audioScenes->currentText();
|
||||||
|
QString transitionName = ui->audioTransitions->currentText();
|
||||||
|
QString audioSourceName = ui->audioSources->currentText();
|
||||||
|
int vol = ui->audioVolumeThreshold->value();
|
||||||
|
|
||||||
|
if (sceneName.isEmpty() || audioSourceName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
|
OBSWeakSource audioSource = GetWeakSourceByQString(audioSourceName);
|
||||||
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
|
QString text = MakeAudioSwitchName(sceneName, transitionName,
|
||||||
|
audioSourceName, vol);
|
||||||
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
|
int idx = audioFindByData(audioSourceName, vol);
|
||||||
|
|
||||||
|
if (idx == -1) {
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
switcher->audioSwitches.emplace_back(
|
||||||
|
source, transition, audioSource, vol,
|
||||||
|
(sceneName == QString(previous_scene_name)),
|
||||||
|
text.toUtf8().constData());
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->audioSwitches);
|
||||||
|
item->setData(Qt::UserRole, v);
|
||||||
|
} else {
|
||||||
|
QListWidgetItem *item = ui->audioSwitches->item(idx);
|
||||||
|
item->setText(text);
|
||||||
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
for (auto &s : switcher->audioSwitches) {
|
||||||
|
if (s.audioSource == audioSource &&
|
||||||
|
s.volumeThreshold == vol) {
|
||||||
|
s.scene = source;
|
||||||
|
s.transition = transition;
|
||||||
|
s.usePreviousScene =
|
||||||
|
(sceneName ==
|
||||||
|
QString(previous_scene_name));
|
||||||
|
s.audioSwitchStr =
|
||||||
|
text.toUtf8().constData();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioRemove_clicked()
|
||||||
|
{
|
||||||
|
QListWidgetItem *item = ui->audioSwitches->currentItem();
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
auto &switches = switcher->audioSwitches;
|
||||||
|
|
||||||
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
|
auto &s = *it;
|
||||||
|
|
||||||
|
if (s.audioSwitchStr == text) {
|
||||||
|
switches.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->audioSwitches->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->audioSwitches->insertItem(
|
||||||
|
index - 1, ui->audioSwitches->takeItem(index));
|
||||||
|
ui->audioSwitches->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->audioSwitches.begin() + index,
|
||||||
|
switcher->audioSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_audioDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->audioSwitches->currentRow();
|
||||||
|
if (index != -1 && index != ui->audioSwitches->count() - 1) {
|
||||||
|
ui->audioSwitches->insertItem(
|
||||||
|
index + 1, ui->audioSwitches->takeItem(index));
|
||||||
|
ui->audioSwitches->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->audioSwitches.begin() + index,
|
||||||
|
switcher->audioSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
|
{
|
||||||
|
if (audioSwitches.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (AudioSwitch &s : audioSwitches) {
|
||||||
|
obs_source_t *as = obs_weak_source_get_source(s.audioSource);
|
||||||
|
const char *name = obs_source_get_name(as);
|
||||||
|
bool audioActive = obs_source_active(as);
|
||||||
|
obs_source_release(as);
|
||||||
|
|
||||||
|
// peak will have a value from -60 db to 0 db
|
||||||
|
bool volumeThresholdreached = (s.peak + 60) * 1.7 >
|
||||||
|
s.volumeThreshold;
|
||||||
|
|
||||||
|
if (volumeThresholdreached && audioActive) {
|
||||||
|
scene = (s.usePreviousScene) ? previousScene : s.scene;
|
||||||
|
transition = s.transition;
|
||||||
|
match = true;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher audio match for %s",
|
||||||
|
name);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveAudioSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *audioArray = obs_data_array_create();
|
||||||
|
for (AudioSwitch &s : switcher->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) {
|
||||||
|
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_array_push_back(audioArray, array_obj);
|
||||||
|
}
|
||||||
|
obs_source_release(sceneSource);
|
||||||
|
obs_source_release(transition);
|
||||||
|
obs_source_release(audioSrouce);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "audioSwitches", audioArray);
|
||||||
|
obs_data_array_release(audioArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadAudioSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->audioSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *audioArray = obs_data_get_array(obj, "audioSwitches");
|
||||||
|
size_t count = obs_data_array_count(audioArray);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
std::string audioSwitchStr =
|
||||||
|
MakeAudioSwitchName(scene, transition, audioSource, vol)
|
||||||
|
.toUtf8()
|
||||||
|
.constData();
|
||||||
|
|
||||||
|
switcher->audioSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition),
|
||||||
|
GetWeakSourceByName(audioSource), vol,
|
||||||
|
(strcmp(scene, previous_scene_name) == 0),
|
||||||
|
audioSwitchStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(audioArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupAudioTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->audioScenes, true);
|
||||||
|
populateTransitionSelection(ui->audioTransitions);
|
||||||
|
|
||||||
|
auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */
|
||||||
|
{
|
||||||
|
QComboBox *combo = reinterpret_cast<QComboBox *>(data);
|
||||||
|
uint32_t flags = obs_source_get_output_flags(source);
|
||||||
|
|
||||||
|
if ((flags & OBS_SOURCE_AUDIO) != 0) {
|
||||||
|
const char *name = obs_source_get_name(source);
|
||||||
|
combo->addItem(name);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
obs_enum_sources(sourceEnum, ui->audioSources);
|
||||||
|
|
||||||
|
for (auto &s : switcher->audioSwitches) {
|
||||||
|
std::string sceneName = (s.usePreviousScene)
|
||||||
|
? previous_scene_name
|
||||||
|
: GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
std::string audioSourceName = GetWeakSourceName(s.audioSource);
|
||||||
|
QString listText = MakeAudioSwitchName(sceneName.c_str(),
|
||||||
|
transitionName.c_str(),
|
||||||
|
audioSourceName.c_str(),
|
||||||
|
s.volumeThreshold);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(listText, ui->audioSwitches);
|
||||||
|
item->setData(Qt::UserRole, listText);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/curl-helper.cpp
Normal file
65
src/curl-helper.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <obs.hpp>
|
||||||
|
|
||||||
|
#include "headers/curl-helper.hpp"
|
||||||
|
|
||||||
|
initFunction f_curl_init = nullptr;
|
||||||
|
setOptFunction f_curl_setopt = nullptr;
|
||||||
|
performFunction f_curl_perform = nullptr;
|
||||||
|
cleanupFunction f_curl_cleanup = nullptr;
|
||||||
|
|
||||||
|
QLibrary *loaded_curl_lib = nullptr;
|
||||||
|
|
||||||
|
bool resolveCurl()
|
||||||
|
{
|
||||||
|
f_curl_init = (initFunction)loaded_curl_lib->resolve("curl_easy_init");
|
||||||
|
f_curl_setopt = (setOptFunction)loaded_curl_lib->resolve("curl_easy_setopt");
|
||||||
|
f_curl_perform =
|
||||||
|
(performFunction)loaded_curl_lib->resolve("curl_easy_perform");
|
||||||
|
f_curl_cleanup =
|
||||||
|
(cleanupFunction)loaded_curl_lib->resolve("curl_easy_cleanup");
|
||||||
|
|
||||||
|
if (f_curl_init && f_curl_setopt && f_curl_perform && f_curl_cleanup) {
|
||||||
|
blog(LOG_INFO, "curl loaded successfully");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
blog(LOG_INFO, "curl symbols not resolved");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loadCurl()
|
||||||
|
{
|
||||||
|
QStringList locations;
|
||||||
|
locations << QDir::currentPath();
|
||||||
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
|
locations << "/usr/lib";
|
||||||
|
locations << "/usr/local/lib";
|
||||||
|
locations << "/usr/lib/x86_64-linux-gnu";
|
||||||
|
locations << "/usr/local/opt/curl/lib";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (QString path : locations) {
|
||||||
|
blog(LOG_INFO, "trying '%s'", path.toUtf8().constData());
|
||||||
|
QFileInfo libPath(QDir(path).absoluteFilePath(CURL_LIBRARY_NAME));
|
||||||
|
|
||||||
|
if (libPath.exists() && libPath.isFile()) {
|
||||||
|
QString libFilePath = libPath.absoluteFilePath();
|
||||||
|
blog(LOG_INFO, "found curl library at '%s'",
|
||||||
|
libFilePath.toUtf8().constData());
|
||||||
|
|
||||||
|
loaded_curl_lib = new QLibrary(libFilePath, nullptr);
|
||||||
|
if (resolveCurl())
|
||||||
|
return true;
|
||||||
|
else {
|
||||||
|
delete loaded_curl_lib;
|
||||||
|
loaded_curl_lib = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blog(LOG_ERROR, "can't find the curl library");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
int SceneSwitcher::executableFindByData(const QString& exe)
|
int SceneSwitcher::executableFindByData(const QString &exe)
|
||||||
{
|
{
|
||||||
int count = ui->executables->count();
|
int count = ui->executables->count();
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->executables->item(i);
|
||||||
QListWidgetItem* item = ui->executables->item(i);
|
|
||||||
QString itemExe = item->data(Qt::UserRole).toString();
|
QString itemExe = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemExe == exe)
|
if (itemExe == exe)
|
||||||
@@ -16,7 +15,6 @@ int SceneSwitcher::executableFindByData(const QString& exe)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneSwitcher::on_executables_currentRowChanged(int idx)
|
void SceneSwitcher::on_executables_currentRowChanged(int idx)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
@@ -24,26 +22,55 @@ void SceneSwitcher::on_executables_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->executables->item(idx);
|
QListWidgetItem *item = ui->executables->item(idx);
|
||||||
|
|
||||||
QString exec = item->data(Qt::UserRole).toString();
|
QString exec = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->executableSwitches)
|
for (auto &s : switcher->executableSwitches) {
|
||||||
{
|
if (exec.compare(s.mExe) == 0) {
|
||||||
if (exec.compare(s.mExe) == 0)
|
|
||||||
{
|
|
||||||
QString sceneName = GetWeakSourceName(s.mScene).c_str();
|
QString sceneName = GetWeakSourceName(s.mScene).c_str();
|
||||||
QString transitionName = GetWeakSourceName(s.mTransition).c_str();
|
QString transitionName =
|
||||||
|
GetWeakSourceName(s.mTransition).c_str();
|
||||||
ui->executableScenes->setCurrentText(sceneName);
|
ui->executableScenes->setCurrentText(sceneName);
|
||||||
ui->executable->setCurrentText(exec);
|
ui->executable->setCurrentText(exec);
|
||||||
ui->executableTransitions->setCurrentText(transitionName);
|
ui->executableTransitions->setCurrentText(
|
||||||
|
transitionName);
|
||||||
ui->requiresFocusCheckBox->setChecked(s.mInFocus);
|
ui->requiresFocusCheckBox->setChecked(s.mInFocus);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_executableUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->executables->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->executables->insertItem(index - 1,
|
||||||
|
ui->executables->takeItem(index));
|
||||||
|
ui->executables->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->executableSwitches.begin() + index,
|
||||||
|
switcher->executableSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_executableDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->executables->currentRow();
|
||||||
|
if (index != -1 && index != ui->executables->count() - 1) {
|
||||||
|
ui->executables->insertItem(index + 1,
|
||||||
|
ui->executables->takeItem(index));
|
||||||
|
ui->executables->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->executableSwitches.begin() + index,
|
||||||
|
switcher->executableSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_executableAdd_clicked()
|
void SceneSwitcher::on_executableAdd_clicked()
|
||||||
{
|
{
|
||||||
@@ -59,30 +86,28 @@ void SceneSwitcher::on_executableAdd_clicked()
|
|||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
QVariant v = QVariant::fromValue(exeName);
|
QVariant v = QVariant::fromValue(exeName);
|
||||||
|
|
||||||
QString text = MakeSwitchNameExecutable(sceneName, exeName, transitionName, inFocus);
|
QString text = MakeSwitchNameExecutable(sceneName, exeName,
|
||||||
|
transitionName, inFocus);
|
||||||
|
|
||||||
int idx = executableFindByData(exeName);
|
int idx = executableFindByData(exeName);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
switcher->executableSwitches.emplace_back(
|
switcher->executableSwitches.emplace_back(
|
||||||
source, transition, exeName.toUtf8().constData(), inFocus);
|
source, transition, exeName.toUtf8().constData(),
|
||||||
|
inFocus);
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->executables);
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->executables);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->executables->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->executables->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->executableSwitches)
|
for (auto &s : switcher->executableSwitches) {
|
||||||
{
|
if (s.mExe == exeName) {
|
||||||
if (s.mExe == exeName)
|
|
||||||
{
|
|
||||||
s.mScene = source;
|
s.mScene = source;
|
||||||
s.mTransition = transition;
|
s.mTransition = transition;
|
||||||
s.mInFocus = inFocus;
|
s.mInFocus = inFocus;
|
||||||
@@ -90,30 +115,25 @@ void SceneSwitcher::on_executableAdd_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->executables->sortItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneSwitcher::on_executableRemove_clicked()
|
void SceneSwitcher::on_executableRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->executables->currentItem();
|
QListWidgetItem *item = ui->executables->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString exe = item->data(Qt::UserRole).toString();
|
QString exe = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->executableSwitches;
|
auto &switches = switcher->executableSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.mExe == exe)
|
if (s.mExe == exe) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -123,18 +143,138 @@ void SceneSwitcher::on_executableRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkExeSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
|
std::string title;
|
||||||
QStringList runningProcesses;
|
QStringList runningProcesses;
|
||||||
|
bool ignored = false;
|
||||||
|
|
||||||
|
// Check if current window is ignored
|
||||||
|
GetCurrentWindowTitle(title);
|
||||||
|
for (auto &window : ignoreWindowsSwitches) {
|
||||||
|
// True if ignored switch equals title
|
||||||
|
bool equals = (title == window);
|
||||||
|
// True if ignored switch matches title
|
||||||
|
bool matches = QString::fromStdString(title).contains(
|
||||||
|
QRegularExpression(QString::fromStdString(window)));
|
||||||
|
|
||||||
|
if (equals || matches) {
|
||||||
|
ignored = true;
|
||||||
|
title = lastTitle;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastTitle = title;
|
||||||
|
|
||||||
|
// Check for match
|
||||||
GetProcessList(runningProcesses);
|
GetProcessList(runningProcesses);
|
||||||
for (ExecutableSceneSwitch& s : executableSwitches)
|
for (ExecutableSceneSwitch &s : executableSwitches) {
|
||||||
{
|
// True if executable switch is running (direct)
|
||||||
if (runningProcesses.contains(s.mExe))
|
bool equals = runningProcesses.contains(s.mExe);
|
||||||
{
|
// True if executable switch is running (regex)
|
||||||
|
bool matches = (runningProcesses.indexOf(
|
||||||
|
QRegularExpression(s.mExe)) != -1);
|
||||||
|
// True if focus is disabled OR switch is focused
|
||||||
|
bool focus = (!s.mInFocus || isInFocus(s.mExe));
|
||||||
|
// True if current window is ignored AND switch equals OR matches last window
|
||||||
|
bool ignore =
|
||||||
|
(ignored && (title == s.mExe.toStdString() ||
|
||||||
|
QString::fromStdString(title).contains(
|
||||||
|
QRegularExpression(s.mExe))));
|
||||||
|
|
||||||
|
if ((equals || matches) && (focus || ignore)) {
|
||||||
|
match = true;
|
||||||
scene = s.mScene;
|
scene = s.mScene;
|
||||||
transition = s.mTransition;
|
transition = s.mTransition;
|
||||||
match = !s.mInFocus || (s.mInFocus && isInFocus(s.mExe));
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher exec match");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveExecutableSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *executableArray = obs_data_array_create();
|
||||||
|
for (ExecutableSceneSwitch &s : switcher->executableSwitches) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
|
||||||
|
obs_source_t *source = obs_weak_source_get_source(s.mScene);
|
||||||
|
obs_source_t *transition =
|
||||||
|
obs_weak_source_get_source(s.mTransition);
|
||||||
|
|
||||||
|
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.mExe.toUtf8());
|
||||||
|
obs_data_set_bool(array_obj, "infocus", s.mInFocus);
|
||||||
|
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);
|
||||||
|
obs_data_array_release(executableArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadExecutableSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->executableSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *executableArray =
|
||||||
|
obs_data_get_array(obj, "executableSwitches");
|
||||||
|
size_t count = obs_data_array_count(executableArray);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(executableArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupExecutableTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->executableScenes, false);
|
||||||
|
populateTransitionSelection(ui->executableTransitions);
|
||||||
|
|
||||||
|
QStringList processes;
|
||||||
|
GetProcessList(processes);
|
||||||
|
for (QString &process : processes)
|
||||||
|
ui->executable->addItem(process);
|
||||||
|
|
||||||
|
for (auto &s : switcher->executableSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.mScene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.mTransition);
|
||||||
|
QString text = MakeSwitchNameExecutable(sceneName.c_str(),
|
||||||
|
s.mExe,
|
||||||
|
transitionName.c_str(),
|
||||||
|
s.mInFocus);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->executables);
|
||||||
|
item->setData(Qt::UserRole, s.mExe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,14 +2,19 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
#include "headers/curl-helper.hpp"
|
||||||
|
|
||||||
|
#define LOCAL_FILE_IDX 0
|
||||||
|
#define REMOTE_FILE_IDX 1
|
||||||
|
|
||||||
void SceneSwitcher::on_browseButton_clicked()
|
void SceneSwitcher::on_browseButton_clicked()
|
||||||
{
|
{
|
||||||
QString path = QFileDialog::getOpenFileName(
|
QString path = QFileDialog::getOpenFileName(
|
||||||
this, tr("Select a file to write to ..."), QDir::currentPath(), tr("Text files (*.txt)"));
|
this, tr("Select a file to write to ..."), QDir::currentPath(),
|
||||||
|
tr("Text files (*.txt)"));
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
ui->writePathLineEdit->setText(path);
|
ui->writePathLineEdit->setText(path);
|
||||||
}
|
}
|
||||||
@@ -19,29 +24,25 @@ void SceneSwitcher::on_readFileCheckBox_stateChanged(int state)
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
if (!state)
|
if (!state) {
|
||||||
{
|
|
||||||
ui->browseButton_2->setDisabled(true);
|
ui->browseButton_2->setDisabled(true);
|
||||||
ui->readPathLineEdit->setDisabled(true);
|
ui->readPathLineEdit->setDisabled(true);
|
||||||
switcher->fileIO.readEnabled = false;
|
switcher->fileIO.readEnabled = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->browseButton_2->setDisabled(false);
|
ui->browseButton_2->setDisabled(false);
|
||||||
ui->readPathLineEdit->setDisabled(false);
|
ui->readPathLineEdit->setDisabled(false);
|
||||||
switcher->fileIO.readEnabled = true;
|
switcher->fileIO.readEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_readPathLineEdit_textChanged(const QString& text)
|
void SceneSwitcher::on_readPathLineEdit_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
if (text.isEmpty())
|
if (text.isEmpty()) {
|
||||||
{
|
|
||||||
switcher->fileIO.readEnabled = false;
|
switcher->fileIO.readEnabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -49,14 +50,13 @@ void SceneSwitcher::on_readPathLineEdit_textChanged(const QString& text)
|
|||||||
switcher->fileIO.readPath = text.toUtf8().constData();
|
switcher->fileIO.readPath = text.toUtf8().constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_writePathLineEdit_textChanged(const QString& text)
|
void SceneSwitcher::on_writePathLineEdit_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
if (text.isEmpty())
|
if (text.isEmpty()) {
|
||||||
{
|
|
||||||
switcher->fileIO.writeEnabled = false;
|
switcher->fileIO.writeEnabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,8 @@ void SceneSwitcher::on_writePathLineEdit_textChanged(const QString& text)
|
|||||||
void SceneSwitcher::on_browseButton_2_clicked()
|
void SceneSwitcher::on_browseButton_2_clicked()
|
||||||
{
|
{
|
||||||
QString path = QFileDialog::getOpenFileName(
|
QString path = QFileDialog::getOpenFileName(
|
||||||
this, tr("Select a file to read from ..."), QDir::currentPath(), tr("Any files (*.*)"));
|
this, tr("Select a file to read from ..."), QDir::currentPath(),
|
||||||
|
tr("Any files (*.*)"));
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
ui->readPathLineEdit->setText(path);
|
ui->readPathLineEdit->setText(path);
|
||||||
}
|
}
|
||||||
@@ -77,31 +78,32 @@ void SwitcherData::writeSceneInfoToFile()
|
|||||||
if (!fileIO.writeEnabled || fileIO.writePath.empty())
|
if (!fileIO.writeEnabled || fileIO.writePath.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
obs_source_t* currentSource = obs_frontend_get_current_scene();
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
|
|
||||||
QFile file(QString::fromStdString(fileIO.writePath));
|
QFile file(QString::fromStdString(fileIO.writePath));
|
||||||
if (file.open(QIODevice::WriteOnly))
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
{
|
const char *msg = obs_source_get_name(currentSource);
|
||||||
const char* msg = obs_source_get_name(currentSource);
|
|
||||||
file.write(msg, qstrlen(msg));
|
file.write(msg, qstrlen(msg));
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
obs_source_release(currentSource);
|
obs_source_release(currentSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkSwitchInfoFromFile(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
void SwitcherData::checkSwitchInfoFromFile(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
if (!fileIO.readEnabled || fileIO.readPath.empty())
|
if (!fileIO.readEnabled || fileIO.readPath.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QFile file(QString::fromStdString(fileIO.readPath));
|
QFile file(QString::fromStdString(fileIO.readPath));
|
||||||
if (file.open(QIODevice::ReadOnly))
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
{
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QString sceneStr = in.readLine();
|
QString sceneStr = in.readLine();
|
||||||
obs_source_t* sceneRead = obs_get_source_by_name(sceneStr.toUtf8().constData());
|
obs_source_t *sceneRead =
|
||||||
if (sceneRead){
|
obs_get_source_by_name(sceneStr.toUtf8().constData());
|
||||||
obs_weak_source_t* sceneReadWs = obs_source_get_weak_source(sceneRead);
|
if (sceneRead) {
|
||||||
|
obs_weak_source_t *sceneReadWs =
|
||||||
|
obs_source_get_weak_source(sceneRead);
|
||||||
|
|
||||||
match = true;
|
match = true;
|
||||||
scene = sceneReadWs;
|
scene = sceneReadWs;
|
||||||
@@ -114,61 +116,110 @@ void SwitcherData::checkSwitchInfoFromFile(bool& match, OBSWeakSource& scene, OB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkFileContent(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||||
|
void *userp)
|
||||||
{
|
{
|
||||||
for (FileSwitch& s : fileSwitches)
|
((std::string *)userp)->append((char *)contents, size * nmemb);
|
||||||
{
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 (QString::compare(s1s, s2s, Qt::CaseSensitive) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkRemoteFileContent(FileSwitch &s)
|
||||||
|
{
|
||||||
|
std::string data = getRemoteData(s.file);
|
||||||
|
bool ret = false;
|
||||||
|
if (s.useRegex) {
|
||||||
|
ret = QString::fromStdString(data).contains(
|
||||||
|
QRegularExpression(QString::fromStdString(s.text)));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
QString t = QString::fromStdString(s.text);
|
||||||
|
QString d = QString::fromStdString(data);
|
||||||
|
|
||||||
|
return compareIgnoringLineEnding(t, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkLocalFileContent(FileSwitch &s)
|
||||||
|
{
|
||||||
|
bool equal = false;
|
||||||
|
QString t = QString::fromStdString(s.text);
|
||||||
|
QFile file(QString::fromStdString(s.file));
|
||||||
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (s.useTime) {
|
||||||
|
QDateTime newLastMod = QFileInfo(file).lastModified();
|
||||||
|
if (s.lastMod == newLastMod)
|
||||||
|
return false;
|
||||||
|
s.lastMod = newLastMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.useRegex) {
|
||||||
|
QTextStream in(&file);
|
||||||
|
QRegExp rx(t);
|
||||||
|
equal = rx.exactMatch(in.readAll());
|
||||||
|
} else {
|
||||||
|
QTextStream in(&file);
|
||||||
|
QString filedata = in.readAll();
|
||||||
|
equal = compareIgnoringLineEnding(filedata, t);
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
return equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::checkFileContent(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
|
{
|
||||||
|
for (FileSwitch &s : fileSwitches) {
|
||||||
bool equal = false;
|
bool equal = false;
|
||||||
QString t = QString::fromStdString(s.text);
|
if (s.remote) {
|
||||||
QFile file(QString::fromStdString(s.file));
|
equal = checkRemoteFileContent(s);
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
} else {
|
||||||
continue;
|
equal = checkLocalFileContent(s);
|
||||||
|
|
||||||
if (s.useTime)
|
|
||||||
{
|
|
||||||
QDateTime newLastMod = QFileInfo(file).lastModified();
|
|
||||||
if (s.lastMod == newLastMod)
|
|
||||||
continue;
|
|
||||||
s.lastMod = newLastMod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.useRegex)
|
|
||||||
{
|
|
||||||
QTextStream in(&file);
|
|
||||||
QRegExp rx(t);
|
|
||||||
equal = rx.exactMatch(in.readAll());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*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 in(&file);
|
|
||||||
QTextStream text(&t);
|
|
||||||
while (!in.atEnd() && !text.atEnd())
|
|
||||||
{
|
|
||||||
QString fileLine = in.readLine();
|
|
||||||
QString textLine = text.readLine();
|
|
||||||
if (QString::compare(fileLine, textLine, Qt::CaseSensitive) != 0)
|
|
||||||
{
|
|
||||||
equal = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
equal = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
if (equal)
|
if (equal) {
|
||||||
{
|
|
||||||
scene = s.scene;
|
scene = s.scene;
|
||||||
transition = s.transition;
|
transition = s.transition;
|
||||||
match = true;
|
match = true;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher file match");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,42 +228,63 @@ void SwitcherData::checkFileContent(bool& match, OBSWeakSource& scene, OBSWeakSo
|
|||||||
void SceneSwitcher::on_browseButton_3_clicked()
|
void SceneSwitcher::on_browseButton_3_clicked()
|
||||||
{
|
{
|
||||||
QString path = QFileDialog::getOpenFileName(
|
QString path = QFileDialog::getOpenFileName(
|
||||||
this, tr("Select a file to read from ..."), QDir::currentPath(), tr("Any files (*.*)"));
|
this, tr("Select a file to read from ..."), QDir::currentPath(),
|
||||||
|
tr("Any files (*.*)"));
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
ui->filePathLineEdit->setText(path);
|
ui->filePathLineEdit->setText(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_fileType_currentIndexChanged(int idx)
|
||||||
|
{
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (idx == LOCAL_FILE_IDX) {
|
||||||
|
ui->browseButton_3->setDisabled(false);
|
||||||
|
ui->fileContentTimeCheckBox->setDisabled(false);
|
||||||
|
ui->remoteFileWarningLabel->hide();
|
||||||
|
}
|
||||||
|
if (idx == REMOTE_FILE_IDX) {
|
||||||
|
ui->browseButton_3->setDisabled(true);
|
||||||
|
ui->fileContentTimeCheckBox->setDisabled(true);
|
||||||
|
ui->remoteFileWarningLabel->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_fileAdd_clicked()
|
void SceneSwitcher::on_fileAdd_clicked()
|
||||||
{
|
{
|
||||||
QString sceneName = ui->fileScenes->currentText();
|
QString sceneName = ui->fileScenes->currentText();
|
||||||
QString transitionName = ui->fileTransitions->currentText();
|
QString transitionName = ui->fileTransitions->currentText();
|
||||||
QString fileName = ui->filePathLineEdit->text();
|
QString fileName = ui->filePathLineEdit->text();
|
||||||
QString text = ui->fileTextEdit->toPlainText();
|
QString text = ui->fileTextEdit->toPlainText();
|
||||||
|
bool remote = (ui->fileType->currentIndex() == REMOTE_FILE_IDX);
|
||||||
bool useRegex = ui->fileContentRegExCheckBox->isChecked();
|
bool useRegex = ui->fileContentRegExCheckBox->isChecked();
|
||||||
bool useTime = ui->fileContentTimeCheckBox->isChecked();
|
bool useTime = ui->fileContentTimeCheckBox->isChecked();
|
||||||
|
|
||||||
if (sceneName.isEmpty() || transitionName.isEmpty() || fileName.isEmpty() || text.isEmpty())
|
if (sceneName.isEmpty() || transitionName.isEmpty() ||
|
||||||
|
fileName.isEmpty() || text.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
QString switchText = MakeFileSwitchName(sceneName, transitionName, fileName, text, useRegex, useTime);
|
QString switchText = MakeFileSwitchName(
|
||||||
|
sceneName, transitionName, fileName, text, useRegex, useTime);
|
||||||
QVariant v = QVariant::fromValue(switchText);
|
QVariant v = QVariant::fromValue(switchText);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(switchText, ui->fileScenesList);
|
new QListWidgetItem(switchText, ui->fileScenesList);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->fileSwitches.emplace_back(
|
switcher->fileSwitches.emplace_back(source, transition,
|
||||||
source, transition, fileName.toUtf8().constData(), text.toUtf8().constData(), useRegex, useTime);
|
fileName.toUtf8().constData(),
|
||||||
|
text.toUtf8().constData(), remote,
|
||||||
|
useRegex, useTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_fileRemove_clicked()
|
void SceneSwitcher::on_fileRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->fileScenesList->currentItem();
|
QListWidgetItem *item = ui->fileScenesList->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -221,9 +293,9 @@ void SceneSwitcher::on_fileRemove_clicked()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
auto& switches = switcher->fileSwitches;
|
auto &switches = switcher->fileSwitches;
|
||||||
switches.erase(switches.begin() + idx);
|
switches.erase(switches.begin() + idx);
|
||||||
}
|
}
|
||||||
qDeleteAll(ui->fileScenesList->selectedItems());
|
qDeleteAll(ui->fileScenesList->selectedItems());
|
||||||
@@ -236,19 +308,168 @@ void SceneSwitcher::on_fileScenesList_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
if (switcher->fileSwitches.size() <= idx)
|
if (switcher->fileSwitches.size() <= idx)
|
||||||
return;
|
return;
|
||||||
FileSwitch s = switcher->fileSwitches[idx];
|
FileSwitch s = switcher->fileSwitches[idx];
|
||||||
|
|
||||||
string sceneName = GetWeakSourceName(s.scene);
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
|
||||||
ui->fileScenes->setCurrentText(sceneName.c_str());
|
ui->fileScenes->setCurrentText(sceneName.c_str());
|
||||||
ui->fileTransitions->setCurrentText(transitionName.c_str());
|
ui->fileTransitions->setCurrentText(transitionName.c_str());
|
||||||
ui->fileTextEdit->setPlainText(s.text.c_str());
|
ui->fileTextEdit->setPlainText(s.text.c_str());
|
||||||
ui->filePathLineEdit->setText(s.file.c_str());
|
ui->filePathLineEdit->setText(s.file.c_str());
|
||||||
|
if (s.remote)
|
||||||
|
ui->fileType->setCurrentIndex(REMOTE_FILE_IDX);
|
||||||
|
else
|
||||||
|
ui->fileType->setCurrentIndex(LOCAL_FILE_IDX);
|
||||||
ui->fileContentRegExCheckBox->setChecked(s.useRegex);
|
ui->fileContentRegExCheckBox->setChecked(s.useRegex);
|
||||||
ui->fileContentTimeCheckBox->setChecked(s.useTime);
|
ui->fileContentTimeCheckBox->setChecked(s.useTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_fileUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->fileScenesList->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->fileScenesList->insertItem(
|
||||||
|
index - 1, ui->fileScenesList->takeItem(index));
|
||||||
|
ui->fileScenesList->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->fileSwitches.begin() + index,
|
||||||
|
switcher->fileSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_fileDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->fileScenesList->currentRow();
|
||||||
|
if (index != -1 && index != ui->fileScenesList->count() - 1) {
|
||||||
|
ui->fileScenesList->insertItem(
|
||||||
|
index + 1, ui->fileScenesList->takeItem(index));
|
||||||
|
ui->fileScenesList->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->fileSwitches.begin() + index,
|
||||||
|
switcher->fileSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveFileSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *fileArray = obs_data_array_create();
|
||||||
|
for (FileSwitch &s : switcher->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);
|
||||||
|
|
||||||
|
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_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());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadFileSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->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");
|
||||||
|
|
||||||
|
switcher->fileSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition), file, text, remote,
|
||||||
|
useRegex, useTime);
|
||||||
|
|
||||||
|
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");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupFileTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->fileScenes, false);
|
||||||
|
populateTransitionSelection(ui->fileTransitions);
|
||||||
|
|
||||||
|
ui->fileType->addItem("local");
|
||||||
|
ui->fileType->addItem("remote");
|
||||||
|
ui->remoteFileWarningLabel->setText(
|
||||||
|
"Note that the scene switcher will try to access the remote location every " +
|
||||||
|
QString::number(switcher->interval) + "ms");
|
||||||
|
|
||||||
|
if (switcher->curl)
|
||||||
|
ui->libcurlWarning->setVisible(false);
|
||||||
|
|
||||||
|
for (auto &s : switcher->fileSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString listText = MakeFileSwitchName(
|
||||||
|
sceneName.c_str(), transitionName.c_str(),
|
||||||
|
s.file.c_str(), s.text.c_str(), s.useRegex, s.useTime);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(listText, ui->fileScenesList);
|
||||||
|
item->setData(Qt::UserRole, listText);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->readPathLineEdit->setText(
|
||||||
|
QString::fromStdString(switcher->fileIO.readPath.c_str()));
|
||||||
|
ui->readFileCheckBox->setChecked(switcher->fileIO.readEnabled);
|
||||||
|
ui->writePathLineEdit->setText(
|
||||||
|
QString::fromStdString(switcher->fileIO.writePath.c_str()));
|
||||||
|
|
||||||
|
if (ui->readFileCheckBox->checkState()) {
|
||||||
|
ui->browseButton_2->setDisabled(false);
|
||||||
|
ui->readPathLineEdit->setDisabled(false);
|
||||||
|
} else {
|
||||||
|
ui->browseButton_2->setDisabled(true);
|
||||||
|
ui->readPathLineEdit->setDisabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
644
src/general.cpp
644
src/general.cpp
@@ -1,24 +1,19 @@
|
|||||||
#include "headers/advanced-scene-switcher.hpp"
|
|
||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
void SceneSwitcher::on_close_clicked()
|
void SceneSwitcher::on_close_clicked()
|
||||||
{
|
{
|
||||||
done(0);
|
done(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_startAtLaunch_toggled(bool value)
|
void SceneSwitcher::UpdateNonMatchingScene(const QString &name)
|
||||||
{
|
{
|
||||||
if (loading)
|
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
|
||||||
return;
|
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
switcher->startAtLaunch = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneSwitcher::UpdateNonMatchingScene(const QString& name)
|
|
||||||
{
|
|
||||||
obs_source_t* scene = obs_get_source_by_name(name.toUtf8().constData());
|
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(scene);
|
|
||||||
|
|
||||||
switcher->nonMatchingScene = ws;
|
switcher->nonMatchingScene = ws;
|
||||||
|
|
||||||
@@ -31,7 +26,7 @@ void SceneSwitcher::on_noMatchDontSwitch_clicked()
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->switchIfNotMatching = NO_SWITCH;
|
switcher->switchIfNotMatching = NO_SWITCH;
|
||||||
ui->noMatchSwitchScene->setEnabled(false);
|
ui->noMatchSwitchScene->setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -41,7 +36,7 @@ void SceneSwitcher::on_noMatchSwitch_clicked()
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->switchIfNotMatching = SWITCH;
|
switcher->switchIfNotMatching = SWITCH;
|
||||||
ui->noMatchSwitchScene->setEnabled(true);
|
ui->noMatchSwitchScene->setEnabled(true);
|
||||||
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
|
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
|
||||||
@@ -52,17 +47,26 @@ void SceneSwitcher::on_noMatchRandomSwitch_clicked()
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->switchIfNotMatching = RANDOM_SWITCH;
|
switcher->switchIfNotMatching = RANDOM_SWITCH;
|
||||||
ui->noMatchSwitchScene->setEnabled(false);
|
ui->noMatchSwitchScene->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(const QString& text)
|
void SceneSwitcher::on_startupBehavior_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
switcher->startupBehavior = (StartupBehavior)index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(const QString &text)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
UpdateNonMatchingScene(text);
|
UpdateNonMatchingScene(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +75,7 @@ void SceneSwitcher::on_checkInterval_valueChanged(int value)
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->interval = value;
|
switcher->interval = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,19 +93,609 @@ void SceneSwitcher::SetStopped()
|
|||||||
|
|
||||||
void SceneSwitcher::on_toggleStartButton_clicked()
|
void SceneSwitcher::on_toggleStartButton_clicked()
|
||||||
{
|
{
|
||||||
if (switcher->th.joinable())
|
if (switcher->th && switcher->th->isRunning()) {
|
||||||
{
|
|
||||||
switcher->Stop();
|
switcher->Stop();
|
||||||
SetStopped();
|
SetStopped();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
switcher->Start();
|
switcher->Start();
|
||||||
SetStarted();
|
SetStarted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::closeEvent(QCloseEvent*)
|
void SceneSwitcher::closeEvent(QCloseEvent *)
|
||||||
{
|
{
|
||||||
obs_frontend_save();
|
obs_frontend_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_autoStopScenes_currentTextChanged(const QString &text)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
UpdateAutoStopScene(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_autoStopSceneCheckBox_stateChanged(int state)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
if (!state) {
|
||||||
|
ui->autoStopScenes->setDisabled(true);
|
||||||
|
switcher->autoStopEnable = false;
|
||||||
|
} else {
|
||||||
|
ui->autoStopScenes->setDisabled(false);
|
||||||
|
switcher->autoStopEnable = true;
|
||||||
|
if (!switcher->autoStopScene)
|
||||||
|
UpdateAutoStopScene(ui->autoStopScenes->currentText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::UpdateAutoStopScene(const QString &name)
|
||||||
|
{
|
||||||
|
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
|
||||||
|
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
|
||||||
|
|
||||||
|
switcher->autoStopScene = ws;
|
||||||
|
|
||||||
|
obs_weak_source_release(ws);
|
||||||
|
obs_source_release(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::autoStopStreamAndRecording()
|
||||||
|
{
|
||||||
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
|
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
|
||||||
|
|
||||||
|
if (ws && autoStopScene == ws) {
|
||||||
|
if (obs_frontend_streaming_active())
|
||||||
|
obs_frontend_streaming_stop();
|
||||||
|
if (obs_frontend_recording_active())
|
||||||
|
obs_frontend_recording_stop();
|
||||||
|
}
|
||||||
|
obs_source_release(currentSource);
|
||||||
|
obs_weak_source_release(ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_autoStartType_currentIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
switcher->autoStartType = (AutoStartType)index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_autoStartScenes_currentTextChanged(const QString &text)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
UpdateAutoStartScene(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_autoStartSceneCheckBox_stateChanged(int state)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
if (!state) {
|
||||||
|
ui->autoStartScenes->setDisabled(true);
|
||||||
|
ui->autoStartType->setDisabled(true);
|
||||||
|
switcher->autoStartEnable = false;
|
||||||
|
} else {
|
||||||
|
ui->autoStartScenes->setDisabled(false);
|
||||||
|
ui->autoStartType->setDisabled(false);
|
||||||
|
switcher->autoStartEnable = true;
|
||||||
|
if (!switcher->autoStartScene)
|
||||||
|
UpdateAutoStartScene(
|
||||||
|
ui->autoStartScenes->currentText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::UpdateAutoStartScene(const QString &name)
|
||||||
|
{
|
||||||
|
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
|
||||||
|
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
|
||||||
|
|
||||||
|
switcher->autoStartScene = ws;
|
||||||
|
|
||||||
|
obs_weak_source_release(ws);
|
||||||
|
obs_source_release(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::autoStartStreamRecording()
|
||||||
|
{
|
||||||
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
|
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
|
||||||
|
|
||||||
|
if (autoStartedRecently)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ws && autoStartScene == ws) {
|
||||||
|
if ((switcher->autoStartType == STREAMING ||
|
||||||
|
switcher->autoStartType == RECORINDGSTREAMING) &&
|
||||||
|
!obs_frontend_streaming_active())
|
||||||
|
obs_frontend_streaming_start();
|
||||||
|
if ((switcher->autoStartType == RECORDING ||
|
||||||
|
switcher->autoStartType == RECORINDGSTREAMING) &&
|
||||||
|
!obs_frontend_recording_active())
|
||||||
|
obs_frontend_recording_start();
|
||||||
|
}
|
||||||
|
obs_source_release(currentSource);
|
||||||
|
obs_weak_source_release(ws);
|
||||||
|
|
||||||
|
autoStartedRecently = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_verboseLogging_stateChanged(int state)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
switcher->verbose = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_exportSettings_clicked()
|
||||||
|
{
|
||||||
|
QString directory = QFileDialog::getSaveFileName(
|
||||||
|
this, tr("Export Advanced Scene Switcher settings to file ..."),
|
||||||
|
QDir::currentPath(), tr("Text files (*.txt)"));
|
||||||
|
if (directory.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFile file(directory);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
obs_data_t *obj = obs_data_create();
|
||||||
|
|
||||||
|
switcher->saveWindowTitleSwitches(obj);
|
||||||
|
switcher->saveScreenRegionSwitches(obj);
|
||||||
|
switcher->savePauseSwitches(obj);
|
||||||
|
switcher->saveSceneRoundTripSwitches(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);
|
||||||
|
|
||||||
|
obs_data_save_json(obj, file.fileName().toUtf8().constData());
|
||||||
|
|
||||||
|
obs_data_release(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_importSettings_clicked()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
QString directory = QFileDialog::getOpenFileName(
|
||||||
|
this,
|
||||||
|
tr("Import Advanced Scene Switcher settings from file ..."),
|
||||||
|
QDir::currentPath(), tr("Text files (*.txt)"));
|
||||||
|
if (directory.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFile file(directory);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
obs_data_t *obj = obs_data_create_from_json_file(
|
||||||
|
file.fileName().toUtf8().constData());
|
||||||
|
|
||||||
|
if (!obj) {
|
||||||
|
QMessageBox Msgbox;
|
||||||
|
Msgbox.setText(
|
||||||
|
"Advanced Scene Switcher failed to import settings");
|
||||||
|
Msgbox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switcher->loadWindowTitleSwitches(obj);
|
||||||
|
switcher->loadScreenRegionSwitches(obj);
|
||||||
|
switcher->loadPauseSwitches(obj);
|
||||||
|
switcher->loadSceneRoundTripSwitches(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);
|
||||||
|
|
||||||
|
obs_data_release(obj);
|
||||||
|
|
||||||
|
QMessageBox Msgbox;
|
||||||
|
Msgbox.setText(
|
||||||
|
"Advanced Scene Switcher settings imported successfully");
|
||||||
|
Msgbox.exec();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int findTabIndex(QTabBar *bar, int pos)
|
||||||
|
{
|
||||||
|
int at = -1;
|
||||||
|
|
||||||
|
QString tabName = "";
|
||||||
|
switch (pos) {
|
||||||
|
case 0:
|
||||||
|
tabName = "General";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tabName = "Transition";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
tabName = "Pause";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
tabName = "Title";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
tabName = "Executable";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
tabName = "Region";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
tabName = "Media";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
tabName = "File";
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
tabName = "Random";
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
tabName = "Time";
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
tabName = "Idle";
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
tabName = "Sequence";
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
tabName = "Audio";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < bar->count(); ++i) {
|
||||||
|
if (bar->tabText(i).compare(tabName) == 0) {
|
||||||
|
at = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (at == -1)
|
||||||
|
blog(LOG_INFO, "Advanced Scene Switcher failed to find tab %s",
|
||||||
|
tabName.toUtf8().constData());
|
||||||
|
|
||||||
|
return at;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setTabOrder()
|
||||||
|
{
|
||||||
|
QTabBar *bar = ui->tabWidget->tabBar();
|
||||||
|
for (int i = 0; i < bar->count(); ++i) {
|
||||||
|
int curPos = findTabIndex(bar, switcher->tabOrder[i]);
|
||||||
|
|
||||||
|
if (i != curPos && curPos != -1)
|
||||||
|
bar->moveTab(curPos, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(bar, &QTabBar::tabMoved, this, &SceneSwitcher::on_tabMoved);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_tabMoved(int from, int to)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
std::swap(switcher->tabOrder[from], switcher->tabOrder[to]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveGeneralSettings(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_set_int(obj, "interval", switcher->interval);
|
||||||
|
|
||||||
|
std::string nonMatchingSceneName =
|
||||||
|
GetWeakSourceName(switcher->nonMatchingScene);
|
||||||
|
obs_data_set_string(obj, "non_matching_scene",
|
||||||
|
nonMatchingSceneName.c_str());
|
||||||
|
obs_data_set_int(obj, "switch_if_not_matching",
|
||||||
|
switcher->switchIfNotMatching);
|
||||||
|
|
||||||
|
obs_data_set_bool(obj, "active", !switcher->stop);
|
||||||
|
obs_data_set_int(obj, "startup_behavior", switcher->startupBehavior);
|
||||||
|
|
||||||
|
std::string autoStopSceneName =
|
||||||
|
GetWeakSourceName(switcher->autoStopScene);
|
||||||
|
obs_data_set_bool(obj, "autoStopEnable", switcher->autoStopEnable);
|
||||||
|
obs_data_set_string(obj, "autoStopSceneName",
|
||||||
|
autoStopSceneName.c_str());
|
||||||
|
|
||||||
|
std::string autoStartSceneName =
|
||||||
|
GetWeakSourceName(switcher->autoStartScene);
|
||||||
|
obs_data_set_bool(obj, "autoStartEnable", switcher->autoStartEnable);
|
||||||
|
obs_data_set_int(obj, "autoStartType", switcher->autoStartType);
|
||||||
|
obs_data_set_string(obj, "autoStartSceneName",
|
||||||
|
autoStartSceneName.c_str());
|
||||||
|
|
||||||
|
obs_data_set_bool(obj, "verbose", switcher->verbose);
|
||||||
|
|
||||||
|
obs_data_set_int(obj, "priority0",
|
||||||
|
switcher->functionNamesByPriority[0]);
|
||||||
|
obs_data_set_int(obj, "priority1",
|
||||||
|
switcher->functionNamesByPriority[1]);
|
||||||
|
obs_data_set_int(obj, "priority2",
|
||||||
|
switcher->functionNamesByPriority[2]);
|
||||||
|
obs_data_set_int(obj, "priority3",
|
||||||
|
switcher->functionNamesByPriority[3]);
|
||||||
|
obs_data_set_int(obj, "priority4",
|
||||||
|
switcher->functionNamesByPriority[4]);
|
||||||
|
obs_data_set_int(obj, "priority5",
|
||||||
|
switcher->functionNamesByPriority[5]);
|
||||||
|
obs_data_set_int(obj, "priority6",
|
||||||
|
switcher->functionNamesByPriority[6]);
|
||||||
|
obs_data_set_int(obj, "priority7",
|
||||||
|
switcher->functionNamesByPriority[7]);
|
||||||
|
obs_data_set_int(obj, "priority8",
|
||||||
|
switcher->functionNamesByPriority[8]);
|
||||||
|
|
||||||
|
obs_data_set_int(obj, "threadPriority", switcher->threadPriority);
|
||||||
|
|
||||||
|
obs_data_set_int(obj, "generalTabPos", switcher->tabOrder[0]);
|
||||||
|
obs_data_set_int(obj, "transitionTabPos", switcher->tabOrder[1]);
|
||||||
|
obs_data_set_int(obj, "pauseTabPos", switcher->tabOrder[2]);
|
||||||
|
obs_data_set_int(obj, "titleTabPos", switcher->tabOrder[3]);
|
||||||
|
obs_data_set_int(obj, "exeTabPos", switcher->tabOrder[4]);
|
||||||
|
obs_data_set_int(obj, "regionTabPos", switcher->tabOrder[5]);
|
||||||
|
obs_data_set_int(obj, "mediaTabPos", switcher->tabOrder[6]);
|
||||||
|
obs_data_set_int(obj, "fileTabPos", switcher->tabOrder[7]);
|
||||||
|
obs_data_set_int(obj, "randomTabPos", switcher->tabOrder[8]);
|
||||||
|
obs_data_set_int(obj, "timeTabPos", switcher->tabOrder[9]);
|
||||||
|
obs_data_set_int(obj, "idleTabPos", switcher->tabOrder[10]);
|
||||||
|
obs_data_set_int(obj, "sequenceTabPos", switcher->tabOrder[11]);
|
||||||
|
obs_data_set_int(obj, "audioTabPos", switcher->tabOrder[12]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadGeneralSettings(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_set_default_int(obj, "interval", default_interval);
|
||||||
|
switcher->interval = obs_data_get_int(obj, "interval");
|
||||||
|
|
||||||
|
obs_data_set_default_int(obj, "switch_if_not_matching", NO_SWITCH);
|
||||||
|
switcher->switchIfNotMatching =
|
||||||
|
(NoMatch)obs_data_get_int(obj, "switch_if_not_matching");
|
||||||
|
std::string nonMatchingScene =
|
||||||
|
obs_data_get_string(obj, "non_matching_scene");
|
||||||
|
switcher->nonMatchingScene =
|
||||||
|
GetWeakSourceByName(nonMatchingScene.c_str());
|
||||||
|
|
||||||
|
switcher->stop = !obs_data_get_bool(obj, "active");
|
||||||
|
switcher->startupBehavior =
|
||||||
|
(StartupBehavior)obs_data_get_int(obj, "startup_behavior");
|
||||||
|
if (switcher->startupBehavior == START)
|
||||||
|
switcher->stop = false;
|
||||||
|
if (switcher->startupBehavior == STOP)
|
||||||
|
switcher->stop = true;
|
||||||
|
|
||||||
|
std::string autoStopScene =
|
||||||
|
obs_data_get_string(obj, "autoStopSceneName");
|
||||||
|
switcher->autoStopEnable = obs_data_get_bool(obj, "autoStopEnable");
|
||||||
|
switcher->autoStopScene = GetWeakSourceByName(autoStopScene.c_str());
|
||||||
|
|
||||||
|
std::string autoStartScene =
|
||||||
|
obs_data_get_string(obj, "autoStartSceneName");
|
||||||
|
switcher->autoStartEnable = obs_data_get_bool(obj, "autoStartEnable");
|
||||||
|
switcher->autoStartType =
|
||||||
|
(AutoStartType)obs_data_get_int(obj, "autoStartType");
|
||||||
|
switcher->autoStartScene = GetWeakSourceByName(autoStartScene.c_str());
|
||||||
|
|
||||||
|
switcher->verbose = obs_data_get_bool(obj, "verbose");
|
||||||
|
|
||||||
|
obs_data_set_default_int(obj, "priority0", default_priority_0);
|
||||||
|
obs_data_set_default_int(obj, "priority1", default_priority_1);
|
||||||
|
obs_data_set_default_int(obj, "priority2", default_priority_2);
|
||||||
|
obs_data_set_default_int(obj, "priority3", default_priority_3);
|
||||||
|
obs_data_set_default_int(obj, "priority4", default_priority_4);
|
||||||
|
obs_data_set_default_int(obj, "priority5", default_priority_5);
|
||||||
|
obs_data_set_default_int(obj, "priority6", default_priority_6);
|
||||||
|
obs_data_set_default_int(obj, "priority7", default_priority_7);
|
||||||
|
obs_data_set_default_int(obj, "priority8", default_priority_8);
|
||||||
|
|
||||||
|
switcher->functionNamesByPriority[0] =
|
||||||
|
(obs_data_get_int(obj, "priority0"));
|
||||||
|
switcher->functionNamesByPriority[1] =
|
||||||
|
(obs_data_get_int(obj, "priority1"));
|
||||||
|
switcher->functionNamesByPriority[2] =
|
||||||
|
(obs_data_get_int(obj, "priority2"));
|
||||||
|
switcher->functionNamesByPriority[3] =
|
||||||
|
(obs_data_get_int(obj, "priority3"));
|
||||||
|
switcher->functionNamesByPriority[4] =
|
||||||
|
(obs_data_get_int(obj, "priority4"));
|
||||||
|
switcher->functionNamesByPriority[5] =
|
||||||
|
(obs_data_get_int(obj, "priority5"));
|
||||||
|
switcher->functionNamesByPriority[6] =
|
||||||
|
(obs_data_get_int(obj, "priority6"));
|
||||||
|
switcher->functionNamesByPriority[7] =
|
||||||
|
(obs_data_get_int(obj, "priority7"));
|
||||||
|
switcher->functionNamesByPriority[8] =
|
||||||
|
(obs_data_get_int(obj, "priority8"));
|
||||||
|
if (!switcher->prioFuncsValid()) {
|
||||||
|
switcher->functionNamesByPriority[0] = (default_priority_0);
|
||||||
|
switcher->functionNamesByPriority[1] = (default_priority_1);
|
||||||
|
switcher->functionNamesByPriority[2] = (default_priority_2);
|
||||||
|
switcher->functionNamesByPriority[3] = (default_priority_3);
|
||||||
|
switcher->functionNamesByPriority[4] = (default_priority_4);
|
||||||
|
switcher->functionNamesByPriority[5] = (default_priority_5);
|
||||||
|
switcher->functionNamesByPriority[6] = (default_priority_6);
|
||||||
|
switcher->functionNamesByPriority[7] = (default_priority_7);
|
||||||
|
switcher->functionNamesByPriority[8] = (default_priority_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_set_default_int(obj, "threadPriority",
|
||||||
|
QThread::NormalPriority);
|
||||||
|
switcher->threadPriority = obs_data_get_int(obj, "threadPriority");
|
||||||
|
|
||||||
|
obs_data_set_default_int(obj, "generalTabPos", 0);
|
||||||
|
obs_data_set_default_int(obj, "transitionTabPos", 1);
|
||||||
|
obs_data_set_default_int(obj, "pauseTabPos", 2);
|
||||||
|
obs_data_set_default_int(obj, "titleTabPos", 3);
|
||||||
|
obs_data_set_default_int(obj, "exeTabPos", 4);
|
||||||
|
obs_data_set_default_int(obj, "regionTabPos", 5);
|
||||||
|
obs_data_set_default_int(obj, "mediaTabPos", 6);
|
||||||
|
obs_data_set_default_int(obj, "fileTabPos", 7);
|
||||||
|
obs_data_set_default_int(obj, "randomTabPos", 8);
|
||||||
|
obs_data_set_default_int(obj, "timeTabPos", 9);
|
||||||
|
obs_data_set_default_int(obj, "idleTabPos", 10);
|
||||||
|
obs_data_set_default_int(obj, "sequenceTabPos", 11);
|
||||||
|
obs_data_set_default_int(obj, "audioTabPos", 12);
|
||||||
|
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "generalTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "transitionTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "pauseTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "titleTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "exeTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "regionTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "mediaTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "fileTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "randomTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "timeTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "idleTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "sequenceTabPos")));
|
||||||
|
switcher->tabOrder.emplace_back(
|
||||||
|
(int)(obs_data_get_int(obj, "audioTabPos")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupGeneralTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->noMatchSwitchScene, false);
|
||||||
|
populateSceneSelection(ui->autoStopScenes, false);
|
||||||
|
populateSceneSelection(ui->autoStartScenes, false);
|
||||||
|
|
||||||
|
if (switcher->switchIfNotMatching == SWITCH) {
|
||||||
|
ui->noMatchSwitch->setChecked(true);
|
||||||
|
ui->noMatchSwitchScene->setEnabled(true);
|
||||||
|
} else if (switcher->switchIfNotMatching == NO_SWITCH) {
|
||||||
|
ui->noMatchDontSwitch->setChecked(true);
|
||||||
|
ui->noMatchSwitchScene->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
ui->noMatchRandomSwitch->setChecked(true);
|
||||||
|
ui->noMatchSwitchScene->setEnabled(false);
|
||||||
|
}
|
||||||
|
ui->noMatchSwitchScene->setCurrentText(
|
||||||
|
GetWeakSourceName(switcher->nonMatchingScene).c_str());
|
||||||
|
ui->checkInterval->setValue(switcher->interval);
|
||||||
|
|
||||||
|
ui->autoStopSceneCheckBox->setChecked(switcher->autoStopEnable);
|
||||||
|
ui->autoStopScenes->setCurrentText(
|
||||||
|
GetWeakSourceName(switcher->autoStopScene).c_str());
|
||||||
|
|
||||||
|
if (ui->autoStopSceneCheckBox->checkState()) {
|
||||||
|
ui->autoStopScenes->setDisabled(false);
|
||||||
|
} else {
|
||||||
|
ui->autoStopScenes->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->autoStartType->addItem("Recording");
|
||||||
|
ui->autoStartType->addItem("Streaming");
|
||||||
|
ui->autoStartType->addItem("Recording and Streaming");
|
||||||
|
|
||||||
|
ui->autoStartSceneCheckBox->setChecked(switcher->autoStartEnable);
|
||||||
|
ui->autoStartScenes->setCurrentText(
|
||||||
|
GetWeakSourceName(switcher->autoStartScene).c_str());
|
||||||
|
ui->autoStartType->setCurrentIndex(switcher->autoStartType);
|
||||||
|
|
||||||
|
if (ui->autoStartSceneCheckBox->checkState()) {
|
||||||
|
ui->autoStartScenes->setDisabled(false);
|
||||||
|
ui->autoStartType->setDisabled(false);
|
||||||
|
} else {
|
||||||
|
ui->autoStartScenes->setDisabled(true);
|
||||||
|
ui->autoStartType->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->verboseLogging->setChecked(switcher->verbose);
|
||||||
|
|
||||||
|
for (int p : switcher->functionNamesByPriority) {
|
||||||
|
std::string s = "";
|
||||||
|
switch (p) {
|
||||||
|
case read_file_func:
|
||||||
|
s = "File Content";
|
||||||
|
break;
|
||||||
|
case round_trip_func:
|
||||||
|
s = "Scene Sequence";
|
||||||
|
break;
|
||||||
|
case idle_func:
|
||||||
|
s = "Idle Detection";
|
||||||
|
break;
|
||||||
|
case exe_func:
|
||||||
|
s = "Executable";
|
||||||
|
break;
|
||||||
|
case screen_region_func:
|
||||||
|
s = "Screen Region";
|
||||||
|
break;
|
||||||
|
case window_title_func:
|
||||||
|
s = "Window Title";
|
||||||
|
break;
|
||||||
|
case media_func:
|
||||||
|
s = "Media";
|
||||||
|
break;
|
||||||
|
case time_func:
|
||||||
|
s = "Time";
|
||||||
|
break;
|
||||||
|
case audio_func:
|
||||||
|
s = "Audio";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QString text(s.c_str());
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->priorityList);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < switcher->threadPriorities.size(); ++i) {
|
||||||
|
ui->threadPriority->addItem(
|
||||||
|
switcher->threadPriorities[i].name.c_str());
|
||||||
|
ui->threadPriority->setItemData(
|
||||||
|
i, switcher->threadPriorities[i].description.c_str(),
|
||||||
|
Qt::ToolTipRole);
|
||||||
|
if (switcher->threadPriority ==
|
||||||
|
switcher->threadPriorities[i].value) {
|
||||||
|
ui->threadPriority->setCurrentText(
|
||||||
|
switcher->threadPriorities[i].name.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->startupBehavior->addItem(
|
||||||
|
"Start the scene switcher if it was running");
|
||||||
|
ui->startupBehavior->addItem("Always start the scene switcher");
|
||||||
|
ui->startupBehavior->addItem("Do not start the scene switcher");
|
||||||
|
|
||||||
|
ui->startupBehavior->setCurrentIndex(switcher->startupBehavior);
|
||||||
|
|
||||||
|
if (switcher->th && switcher->th->isRunning())
|
||||||
|
SetStarted();
|
||||||
|
else
|
||||||
|
SetStopped();
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "ui_advanced-scene-switcher.h"
|
#include "ui_advanced-scene-switcher.h"
|
||||||
#endif
|
#endif
|
||||||
#include "switcher-data-structs.hpp"
|
#include "switcher-data-structs.hpp"
|
||||||
|
#include "volume-control.hpp"
|
||||||
|
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ class SceneSwitcher : public QDialog {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<Ui_SceneSwitcher> ui;
|
std::unique_ptr<Ui_SceneSwitcher> ui;
|
||||||
|
VolControl *volMeter = nullptr;
|
||||||
bool loading = true;
|
bool loading = true;
|
||||||
|
|
||||||
SceneSwitcher(QWidget *parent);
|
SceneSwitcher(QWidget *parent);
|
||||||
@@ -42,28 +44,55 @@ public:
|
|||||||
int executableFindByData(const QString &exe);
|
int executableFindByData(const QString &exe);
|
||||||
int IgnoreIdleWindowsFindByData(const QString &window);
|
int IgnoreIdleWindowsFindByData(const QString &window);
|
||||||
int randomFindByData(const QString &scene);
|
int randomFindByData(const QString &scene);
|
||||||
int timeFindByData(const QString &timeStr);
|
int timeFindByData(const timeTrigger &trigger, const QTime &time);
|
||||||
|
int audioFindByData(const QString &source, const int &volume);
|
||||||
|
|
||||||
void UpdateNonMatchingScene(const QString &name);
|
void UpdateNonMatchingScene(const QString &name);
|
||||||
void UpdateAutoStopScene(const QString &name);
|
void UpdateAutoStopScene(const QString &name);
|
||||||
|
void UpdateAutoStartScene(const QString &name);
|
||||||
void UpdateIdleDataTransition(const QString &name);
|
void UpdateIdleDataTransition(const QString &name);
|
||||||
void UpdateIdleDataScene(const QString &name);
|
void UpdateIdleDataScene(const QString &name);
|
||||||
|
void SetAudioVolumeMeter(const QString &name);
|
||||||
|
|
||||||
|
void loadUI();
|
||||||
|
void populateSceneSelection(QComboBox *sel, bool addPrevious);
|
||||||
|
void populateTransitionSelection(QComboBox *sel);
|
||||||
|
void populateWindowSelection(QComboBox *sel);
|
||||||
|
void setupGeneralTab();
|
||||||
|
void setupTitleTab();
|
||||||
|
void setupExecutableTab();
|
||||||
|
void setupRegionTab();
|
||||||
|
void setupPauseTab();
|
||||||
|
void setupSequenceTab();
|
||||||
|
void setupTransitionsTab();
|
||||||
|
void setupIdleTab();
|
||||||
|
void setupRandomTab();
|
||||||
|
void setupMediaTab();
|
||||||
|
void setupFileTab();
|
||||||
|
void setupTimeTab();
|
||||||
|
void setupAudioTab();
|
||||||
|
void setTabOrder();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_switches_currentRowChanged(int idx);
|
void on_switches_currentRowChanged(int idx);
|
||||||
|
void on_up_clicked();
|
||||||
|
void on_down_clicked();
|
||||||
void on_add_clicked();
|
void on_add_clicked();
|
||||||
void on_remove_clicked();
|
void on_remove_clicked();
|
||||||
void on_noMatchDontSwitch_clicked();
|
void on_noMatchDontSwitch_clicked();
|
||||||
void on_noMatchSwitch_clicked();
|
void on_noMatchSwitch_clicked();
|
||||||
void on_noMatchRandomSwitch_clicked();
|
void on_noMatchRandomSwitch_clicked();
|
||||||
void on_startAtLaunch_toggled(bool value);
|
void on_startupBehavior_currentIndexChanged(int index);
|
||||||
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
|
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
|
||||||
void on_checkInterval_valueChanged(int value);
|
void on_checkInterval_valueChanged(int value);
|
||||||
void on_toggleStartButton_clicked();
|
void on_toggleStartButton_clicked();
|
||||||
|
void on_tabMoved(int from, int to);
|
||||||
|
|
||||||
void on_screenRegions_currentRowChanged(int idx);
|
void on_screenRegions_currentRowChanged(int idx);
|
||||||
void on_screenRegionAdd_clicked();
|
void on_screenRegionAdd_clicked();
|
||||||
void on_screenRegionRemove_clicked();
|
void on_screenRegionRemove_clicked();
|
||||||
|
void on_screenRegionUp_clicked();
|
||||||
|
void on_screenRegionDown_clicked();
|
||||||
|
|
||||||
void on_pauseScenes_currentRowChanged(int idx);
|
void on_pauseScenes_currentRowChanged(int idx);
|
||||||
void on_pauseScenesAdd_clicked();
|
void on_pauseScenesAdd_clicked();
|
||||||
@@ -82,23 +111,39 @@ public slots:
|
|||||||
void on_sceneRoundTripRemove_clicked();
|
void on_sceneRoundTripRemove_clicked();
|
||||||
void on_sceneRoundTripSave_clicked();
|
void on_sceneRoundTripSave_clicked();
|
||||||
void on_sceneRoundTripLoad_clicked();
|
void on_sceneRoundTripLoad_clicked();
|
||||||
|
void on_sceneRoundTripUp_clicked();
|
||||||
|
void on_sceneRoundTripDown_clicked();
|
||||||
|
void on_sceneRoundTripDelayUnits_currentIndexChanged(int index);
|
||||||
|
|
||||||
void on_autoStopSceneCheckBox_stateChanged(int state);
|
void on_autoStopSceneCheckBox_stateChanged(int state);
|
||||||
void on_autoStopScenes_currentTextChanged(const QString &text);
|
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_verboseLogging_stateChanged(int state);
|
||||||
|
|
||||||
|
void on_exportSettings_clicked();
|
||||||
|
void on_importSettings_clicked();
|
||||||
|
|
||||||
void on_sceneTransitions_currentRowChanged(int idx);
|
void on_sceneTransitions_currentRowChanged(int idx);
|
||||||
void on_transitionsAdd_clicked();
|
void on_transitionsAdd_clicked();
|
||||||
void on_transitionsRemove_clicked();
|
void on_transitionsRemove_clicked();
|
||||||
void on_defaultTransitions_currentRowChanged(int idx);
|
void on_defaultTransitions_currentRowChanged(int idx);
|
||||||
void on_defaultTransitionsAdd_clicked();
|
void on_defaultTransitionsAdd_clicked();
|
||||||
void on_defaultTransitionsRemove_clicked();
|
void on_defaultTransitionsRemove_clicked();
|
||||||
|
void on_transitionOverridecheckBox_stateChanged(int state);
|
||||||
|
|
||||||
void on_browseButton_clicked();
|
void on_browseButton_clicked();
|
||||||
void on_readFileCheckBox_stateChanged(int state);
|
void on_readFileCheckBox_stateChanged(int state);
|
||||||
|
void on_fileType_currentIndexChanged(int idx);
|
||||||
void on_readPathLineEdit_textChanged(const QString &text);
|
void on_readPathLineEdit_textChanged(const QString &text);
|
||||||
void on_writePathLineEdit_textChanged(const QString &text);
|
void on_writePathLineEdit_textChanged(const QString &text);
|
||||||
void on_browseButton_2_clicked();
|
void on_browseButton_2_clicked();
|
||||||
|
|
||||||
|
void on_executableUp_clicked();
|
||||||
|
void on_executableDown_clicked();
|
||||||
void on_executableAdd_clicked();
|
void on_executableAdd_clicked();
|
||||||
void on_executableRemove_clicked();
|
void on_executableRemove_clicked();
|
||||||
void on_executables_currentRowChanged(int idx);
|
void on_executables_currentRowChanged(int idx);
|
||||||
@@ -119,33 +164,52 @@ public slots:
|
|||||||
void on_fileRemove_clicked();
|
void on_fileRemove_clicked();
|
||||||
void on_fileScenesList_currentRowChanged(int idx);
|
void on_fileScenesList_currentRowChanged(int idx);
|
||||||
void on_browseButton_3_clicked();
|
void on_browseButton_3_clicked();
|
||||||
|
void on_fileUp_clicked();
|
||||||
|
void on_fileDown_clicked();
|
||||||
|
|
||||||
|
void on_mediaSwitches_currentRowChanged(int idx);
|
||||||
void on_mediaAdd_clicked();
|
void on_mediaAdd_clicked();
|
||||||
void on_mediaRemove_clicked();
|
void on_mediaRemove_clicked();
|
||||||
|
void on_mediaUp_clicked();
|
||||||
|
void on_mediaDown_clicked();
|
||||||
|
void on_mediaTimeRestrictions_currentIndexChanged(int idx);
|
||||||
|
|
||||||
void on_timeSwitches_currentRowChanged(int idx);
|
void on_timeSwitches_currentRowChanged(int idx);
|
||||||
void on_timeAdd_clicked();
|
void on_timeAdd_clicked();
|
||||||
void on_timeRemove_clicked();
|
void on_timeRemove_clicked();
|
||||||
|
void on_timeUp_clicked();
|
||||||
|
void on_timeDown_clicked();
|
||||||
|
|
||||||
|
void on_audioAdd_clicked();
|
||||||
|
void on_audioRemove_clicked();
|
||||||
|
void on_audioUp_clicked();
|
||||||
|
void on_audioDown_clicked();
|
||||||
|
void on_audioSwitches_currentRowChanged(int idx);
|
||||||
|
void on_audioSources_currentTextChanged(const QString &text);
|
||||||
|
|
||||||
void on_priorityUp_clicked();
|
void on_priorityUp_clicked();
|
||||||
void on_priorityDown_clicked();
|
void on_priorityDown_clicked();
|
||||||
|
void on_threadPriority_currentTextChanged(const QString &text);
|
||||||
|
|
||||||
void updateScreenRegionCursorPos();
|
void updateScreenRegionCursorPos();
|
||||||
|
|
||||||
void on_close_clicked();
|
void on_close_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Windowtitle helper
|
* Windowtitle helper
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
void GetWindowList(std::vector<std::string> &windows);
|
void GetWindowList(std::vector<std::string> &windows);
|
||||||
|
void GetWindowList(QStringList &windows); // Overloaded
|
||||||
void GetCurrentWindowTitle(std::string &title);
|
void GetCurrentWindowTitle(std::string &title);
|
||||||
bool isFullscreen();
|
bool isFullscreen(std::string &title);
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Screenregion helper
|
* Screenregion helper
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
pair<int, int> getCursorPos();
|
std::pair<int, int> getCursorPos();
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Idle detection helper
|
* Idle detection helper
|
||||||
@@ -156,7 +220,7 @@ int secondsSinceLastInput();
|
|||||||
* Executable helper
|
* Executable helper
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
void GetProcessList(QStringList &processes);
|
void GetProcessList(QStringList &processes);
|
||||||
bool isInFocus(const QString &exeToCheck);
|
bool isInFocus(const QString &executable);
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Sceneswitch helper
|
* Sceneswitch helper
|
||||||
@@ -164,18 +228,29 @@ bool isInFocus(const QString &exeToCheck);
|
|||||||
struct obs_weak_source;
|
struct obs_weak_source;
|
||||||
typedef struct obs_weak_source obs_weak_source_t;
|
typedef struct obs_weak_source obs_weak_source_t;
|
||||||
|
|
||||||
obs_weak_source_t *getNextTransition(obs_weak_source_t *scene1,
|
typedef struct transitionData {
|
||||||
obs_weak_source_t *scene2);
|
std::string name = "";
|
||||||
|
int duration = 0;
|
||||||
|
} transitionData;
|
||||||
|
|
||||||
|
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 restoreTransitionOverride(obs_source_t *scene, transitionData td);
|
||||||
|
|
||||||
void switchScene(OBSWeakSource &scene, OBSWeakSource &transition,
|
void switchScene(OBSWeakSource &scene, OBSWeakSource &transition,
|
||||||
unique_lock<mutex> &lock);
|
bool &transitionOverrideOverride,
|
||||||
|
std::unique_lock<std::mutex> &lock);
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Hotkey helper
|
* Hotkey helper
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#define TOGGLE_HOTKEY_PATH "hotkey_toggle.txt"
|
constexpr auto toggle_hotkey_path = "hotkey_toggle.txt";
|
||||||
#define STOP_HOTKEY_PATH "hotkey_stop.txt"
|
constexpr auto stop_hotkey_path = "hotkey_stop.txt";
|
||||||
#define START_HOTKEY_PATH "hotkey_start.txt"
|
constexpr auto start_hotkey_path = "hotkey_start.txt";
|
||||||
|
|
||||||
void stopHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
|
void stopHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
|
||||||
bool pressed);
|
bool pressed);
|
||||||
@@ -183,7 +258,7 @@ void startHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
|
|||||||
bool pressed);
|
bool pressed);
|
||||||
void startStopToggleHotkeyFunc(void *data, obs_hotkey_id id,
|
void startStopToggleHotkeyFunc(void *data, obs_hotkey_id id,
|
||||||
obs_hotkey_t *hotkey, bool pressed);
|
obs_hotkey_t *hotkey, bool pressed);
|
||||||
void loadKeybinding(obs_hotkey_id hotkeyId, string path);
|
void loadKeybinding(obs_hotkey_id hotkeyId, std::string path);
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Main SwitcherData
|
* Main SwitcherData
|
||||||
|
|||||||
26
src/headers/curl-helper.hpp
Normal file
26
src/headers/curl-helper.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <QLibrary>
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
#define CURL_LIBRARY_NAME "libcurl.dll"
|
||||||
|
#elif __APPLE__
|
||||||
|
#define CURL_LIBRARY_NAME "libcurl.4.dylib"
|
||||||
|
#else
|
||||||
|
#define CURL_LIBRARY_NAME "libcurl.so.4"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef CURL *(*initFunction)(void);
|
||||||
|
typedef CURLcode (*setOptFunction)(CURL *, CURLoption, ...);
|
||||||
|
typedef CURLcode (*performFunction)(CURL *);
|
||||||
|
typedef void (*cleanupFunction)(CURL *);
|
||||||
|
|
||||||
|
extern initFunction f_curl_init;
|
||||||
|
extern setOptFunction f_curl_setopt;
|
||||||
|
extern performFunction f_curl_perform;
|
||||||
|
extern cleanupFunction f_curl_cleanup;
|
||||||
|
|
||||||
|
extern QLibrary *loaded_curl_lib;
|
||||||
|
|
||||||
|
bool resolveCurl();
|
||||||
|
bool loadCurl();
|
||||||
@@ -3,55 +3,58 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <thread>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <curl/curl.h>
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#define DEFAULT_INTERVAL 300
|
constexpr auto default_interval = 300;
|
||||||
|
|
||||||
#define DEFAULT_IDLE_TIME 60
|
constexpr auto default_idle_time = 60;
|
||||||
|
|
||||||
#define PREVIOUS_SCENE_NAME "Previous Scene"
|
constexpr auto previous_scene_name = "Previous Scene";
|
||||||
|
|
||||||
#define READ_FILE_FUNC 0
|
constexpr auto read_file_func = 0;
|
||||||
#define ROUND_TRIP_FUNC 1
|
constexpr auto round_trip_func = 1;
|
||||||
#define IDLE_FUNC 2
|
constexpr auto idle_func = 2;
|
||||||
#define EXE_FUNC 3
|
constexpr auto exe_func = 3;
|
||||||
#define SCREEN_REGION_FUNC 4
|
constexpr auto screen_region_func = 4;
|
||||||
#define WINDOW_TITLE_FUNC 5
|
constexpr auto window_title_func = 5;
|
||||||
#define MEDIA_FUNC 6
|
constexpr auto media_func = 6;
|
||||||
#define TIME_FUNC 7
|
constexpr auto time_func = 7;
|
||||||
|
constexpr auto audio_func = 8;
|
||||||
|
|
||||||
#define DEFAULT_PRIORITY_0 READ_FILE_FUNC
|
constexpr auto default_priority_0 = read_file_func;
|
||||||
#define DEFAULT_PRIORITY_1 ROUND_TRIP_FUNC
|
constexpr auto default_priority_1 = round_trip_func;
|
||||||
#define DEFAULT_PRIORITY_2 IDLE_FUNC
|
constexpr auto default_priority_2 = idle_func;
|
||||||
#define DEFAULT_PRIORITY_3 EXE_FUNC
|
constexpr auto default_priority_3 = exe_func;
|
||||||
#define DEFAULT_PRIORITY_4 SCREEN_REGION_FUNC
|
constexpr auto default_priority_4 = screen_region_func;
|
||||||
#define DEFAULT_PRIORITY_5 WINDOW_TITLE_FUNC
|
constexpr auto default_priority_5 = window_title_func;
|
||||||
#define DEFAULT_PRIORITY_6 MEDIA_FUNC
|
constexpr auto default_priority_6 = media_func;
|
||||||
#define DEFAULT_PRIORITY_7 TIME_FUNC
|
constexpr auto default_priority_7 = time_func;
|
||||||
|
constexpr auto default_priority_8 = audio_func;
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Data structs for each scene switching method
|
* Data structs for each scene switching method
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
struct WindowSceneSwitch {
|
struct WindowSceneSwitch {
|
||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
string window;
|
std::string window;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
|
bool focus;
|
||||||
|
|
||||||
inline WindowSceneSwitch(OBSWeakSource scene_, const char *window_,
|
inline WindowSceneSwitch(OBSWeakSource scene_, const char *window_,
|
||||||
OBSWeakSource transition_, bool fullscreen_)
|
OBSWeakSource transition_, bool fullscreen_,
|
||||||
|
bool focus_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
window(window_),
|
window(window_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
fullscreen(fullscreen_)
|
fullscreen(fullscreen_),
|
||||||
|
focus(focus_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -77,12 +80,12 @@ struct ScreenRegionSwitch {
|
|||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
int minX, minY, maxX, maxY;
|
int minX, minY, maxX, maxY;
|
||||||
string regionStr;
|
std::string regionStr;
|
||||||
|
|
||||||
inline ScreenRegionSwitch(OBSWeakSource scene_,
|
inline ScreenRegionSwitch(OBSWeakSource scene_,
|
||||||
OBSWeakSource transition_, int minX_,
|
OBSWeakSource transition_, int minX_,
|
||||||
int minY_, int maxX_, int maxY_,
|
int minY_, int maxX_, int maxY_,
|
||||||
string regionStr_)
|
std::string regionStr_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
minX(minX_),
|
minX(minX_),
|
||||||
@@ -98,14 +101,14 @@ struct SceneRoundTripSwitch {
|
|||||||
OBSWeakSource scene1;
|
OBSWeakSource scene1;
|
||||||
OBSWeakSource scene2;
|
OBSWeakSource scene2;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
int delay;
|
double delay;
|
||||||
bool usePreviousScene;
|
bool usePreviousScene;
|
||||||
string sceneRoundTripStr;
|
std::string sceneRoundTripStr;
|
||||||
|
|
||||||
inline SceneRoundTripSwitch(OBSWeakSource scene1_,
|
inline SceneRoundTripSwitch(OBSWeakSource scene1_,
|
||||||
OBSWeakSource scene2_,
|
OBSWeakSource scene2_,
|
||||||
OBSWeakSource transition_, int delay_,
|
OBSWeakSource transition_, double delay_,
|
||||||
bool usePreviousScene_, string str)
|
bool usePreviousScene_, std::string str)
|
||||||
: scene1(scene1_),
|
: scene1(scene1_),
|
||||||
scene2(scene2_),
|
scene2(scene2_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
@@ -120,10 +123,10 @@ struct RandomSwitch {
|
|||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
double delay;
|
double delay;
|
||||||
string randomSwitchStr;
|
std::string randomSwitchStr;
|
||||||
|
|
||||||
inline RandomSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
inline RandomSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||||
double delay_, string str)
|
double delay_, std::string str)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
delay(delay_),
|
delay(delay_),
|
||||||
@@ -136,11 +139,11 @@ struct SceneTransition {
|
|||||||
OBSWeakSource scene1;
|
OBSWeakSource scene1;
|
||||||
OBSWeakSource scene2;
|
OBSWeakSource scene2;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
string sceneTransitionStr;
|
std::string sceneTransitionStr;
|
||||||
|
|
||||||
inline SceneTransition(OBSWeakSource scene1_, OBSWeakSource scene2_,
|
inline SceneTransition(OBSWeakSource scene1_, OBSWeakSource scene2_,
|
||||||
OBSWeakSource transition_,
|
OBSWeakSource transition_,
|
||||||
string sceneTransitionStr_)
|
std::string sceneTransitionStr_)
|
||||||
: scene1(scene1_),
|
: scene1(scene1_),
|
||||||
scene2(scene2_),
|
scene2(scene2_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
@@ -152,11 +155,11 @@ struct SceneTransition {
|
|||||||
struct DefaultSceneTransition {
|
struct DefaultSceneTransition {
|
||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
string sceneTransitionStr;
|
std::string sceneTransitionStr;
|
||||||
|
|
||||||
inline DefaultSceneTransition(OBSWeakSource scene_,
|
inline DefaultSceneTransition(OBSWeakSource scene_,
|
||||||
OBSWeakSource transition_,
|
OBSWeakSource transition_,
|
||||||
string sceneTransitionStr_)
|
std::string sceneTransitionStr_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
sceneTransitionStr(sceneTransitionStr_)
|
sceneTransitionStr(sceneTransitionStr_)
|
||||||
@@ -167,19 +170,21 @@ struct DefaultSceneTransition {
|
|||||||
struct FileSwitch {
|
struct FileSwitch {
|
||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
string file;
|
std::string file;
|
||||||
string text;
|
std::string text;
|
||||||
|
bool remote = false;
|
||||||
bool useRegex = false;
|
bool useRegex = false;
|
||||||
bool useTime = false;
|
bool useTime = false;
|
||||||
QDateTime lastMod;
|
QDateTime lastMod;
|
||||||
|
|
||||||
inline FileSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
inline FileSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||||
const char *file_, const char *text_, bool useRegex_,
|
const char *file_, const char *text_, bool remote_,
|
||||||
bool useTime_)
|
bool useRegex_, bool useTime_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
file(file_),
|
file(file_),
|
||||||
text(text_),
|
text(text_),
|
||||||
|
remote(remote_),
|
||||||
useRegex(useRegex_),
|
useRegex(useRegex_),
|
||||||
useTime(useTime_),
|
useTime(useTime_),
|
||||||
lastMod()
|
lastMod()
|
||||||
@@ -189,14 +194,14 @@ struct FileSwitch {
|
|||||||
|
|
||||||
struct FileIOData {
|
struct FileIOData {
|
||||||
bool readEnabled = false;
|
bool readEnabled = false;
|
||||||
string readPath;
|
std::string readPath;
|
||||||
bool writeEnabled = false;
|
bool writeEnabled = false;
|
||||||
string writePath;
|
std::string writePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IdleData {
|
struct IdleData {
|
||||||
bool idleEnable = false;
|
bool idleEnable = false;
|
||||||
int time = DEFAULT_IDLE_TIME;
|
int time = default_idle_time;
|
||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
bool usePreviousScene;
|
bool usePreviousScene;
|
||||||
@@ -208,22 +213,24 @@ struct MediaSwitch {
|
|||||||
OBSWeakSource source;
|
OBSWeakSource source;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
obs_media_state state;
|
obs_media_state state;
|
||||||
uint64_t time;
|
int64_t time;
|
||||||
time_restriction restriction;
|
time_restriction restriction;
|
||||||
bool matched;
|
bool matched;
|
||||||
bool usePreviousScene;
|
bool usePreviousScene;
|
||||||
|
std::string mediaSwitchStr;
|
||||||
|
|
||||||
inline MediaSwitch(OBSWeakSource scene_, OBSWeakSource source_,
|
inline MediaSwitch(OBSWeakSource scene_, OBSWeakSource source_,
|
||||||
OBSWeakSource transition_, obs_media_state state_,
|
OBSWeakSource transition_, obs_media_state state_,
|
||||||
time_restriction restriction_, uint64_t time_,
|
time_restriction restriction_, uint64_t time_,
|
||||||
bool usePreviousScene_)
|
bool usePreviousScene_, std::string mediaSwitchStr_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
source(source_),
|
source(source_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
state(state_),
|
state(state_),
|
||||||
restriction(restriction_),
|
restriction(restriction_),
|
||||||
time(time_),
|
time(time_),
|
||||||
usePreviousScene(usePreviousScene_)
|
usePreviousScene(usePreviousScene_),
|
||||||
|
mediaSwitchStr(mediaSwitchStr_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -231,16 +238,17 @@ struct MediaSwitch {
|
|||||||
struct TimeSwitch {
|
struct TimeSwitch {
|
||||||
OBSWeakSource scene;
|
OBSWeakSource scene;
|
||||||
OBSWeakSource transition;
|
OBSWeakSource transition;
|
||||||
|
timeTrigger trigger;
|
||||||
QTime time;
|
QTime time;
|
||||||
bool matched;
|
|
||||||
bool usePreviousScene;
|
bool usePreviousScene;
|
||||||
string timeSwitchStr;
|
std::string timeSwitchStr;
|
||||||
|
|
||||||
inline TimeSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
inline TimeSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||||
QTime time_, bool usePreviousScene_,
|
timeTrigger trigger_, QTime time_,
|
||||||
string timeSwitchStr_)
|
bool usePreviousScene_, std::string timeSwitchStr_)
|
||||||
: scene(scene_),
|
: scene(scene_),
|
||||||
transition(transition_),
|
transition(transition_),
|
||||||
|
trigger(trigger_),
|
||||||
time(time_),
|
time(time_),
|
||||||
usePreviousScene(usePreviousScene_),
|
usePreviousScene(usePreviousScene_),
|
||||||
timeSwitchStr(timeSwitchStr_)
|
timeSwitchStr(timeSwitchStr_)
|
||||||
@@ -248,22 +256,133 @@ struct TimeSwitch {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AudioSwitch {
|
||||||
|
OBSWeakSource scene;
|
||||||
|
OBSWeakSource audioSource;
|
||||||
|
OBSWeakSource transition;
|
||||||
|
int volumeThreshold;
|
||||||
|
float peak;
|
||||||
|
bool usePreviousScene;
|
||||||
|
obs_volmeter_t *volmeter;
|
||||||
|
std::string audioSwitchStr;
|
||||||
|
|
||||||
|
static void 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);
|
||||||
|
AudioSwitch *s = static_cast<AudioSwitch *>(data);
|
||||||
|
|
||||||
|
s->peak = peak[0];
|
||||||
|
for (int i = 1; i < MAX_AUDIO_CHANNELS; i++)
|
||||||
|
if (peak[i] > s->peak)
|
||||||
|
s->peak = peak[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||||
|
OBSWeakSource audioSource_, int volumeThreshold_,
|
||||||
|
bool usePreviousScene_, std::string audioSwitchStr_)
|
||||||
|
: scene(scene_),
|
||||||
|
transition(transition_),
|
||||||
|
audioSource(audioSource_),
|
||||||
|
volumeThreshold(volumeThreshold_),
|
||||||
|
usePreviousScene(usePreviousScene_),
|
||||||
|
audioSwitchStr(audioSwitchStr_)
|
||||||
|
{
|
||||||
|
volmeter = obs_volmeter_create(OBS_FADER_LOG);
|
||||||
|
obs_volmeter_add_callback(volmeter, setVolumeLevel, this);
|
||||||
|
obs_source_t *as = obs_weak_source_get_source(audioSource);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioSwitch(const AudioSwitch &other)
|
||||||
|
: scene(other.scene),
|
||||||
|
transition(other.transition),
|
||||||
|
audioSource(other.audioSource),
|
||||||
|
volumeThreshold(other.volumeThreshold),
|
||||||
|
usePreviousScene(other.usePreviousScene),
|
||||||
|
audioSwitchStr(other.audioSwitchStr)
|
||||||
|
{
|
||||||
|
volmeter = obs_volmeter_create(OBS_FADER_LOG);
|
||||||
|
obs_volmeter_add_callback(volmeter, setVolumeLevel, this);
|
||||||
|
obs_source_t *as =
|
||||||
|
obs_weak_source_get_source(other.audioSource);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioSwitch(AudioSwitch &&other)
|
||||||
|
: scene(other.scene),
|
||||||
|
transition(other.transition),
|
||||||
|
audioSource(other.audioSource),
|
||||||
|
volumeThreshold(other.volumeThreshold),
|
||||||
|
usePreviousScene(other.usePreviousScene),
|
||||||
|
audioSwitchStr(other.audioSwitchStr),
|
||||||
|
volmeter(other.volmeter)
|
||||||
|
{
|
||||||
|
other.volmeter = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ~AudioSwitch()
|
||||||
|
{
|
||||||
|
obs_volmeter_remove_callback(volmeter, setVolumeLevel, this);
|
||||||
|
obs_volmeter_destroy(volmeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioSwitch &operator=(const AudioSwitch &other)
|
||||||
|
{
|
||||||
|
return *this = AudioSwitch(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioSwitch &operator=(AudioSwitch &&other) noexcept
|
||||||
|
{
|
||||||
|
if (this == &other) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
obs_volmeter_destroy(volmeter);
|
||||||
|
volmeter = other.volmeter;
|
||||||
|
other.volmeter = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
|
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;
|
||||||
|
|
||||||
|
class SwitcherThread;
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* SwitcherData
|
* SwitcherData
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
struct SwitcherData {
|
struct SwitcherData {
|
||||||
thread th;
|
SwitcherThread *th = nullptr;
|
||||||
condition_variable cv;
|
|
||||||
mutex m;
|
std::condition_variable cv;
|
||||||
|
std::mutex m;
|
||||||
bool transitionActive = false;
|
bool transitionActive = false;
|
||||||
bool waitForTransition = false;
|
bool waitForTransition = false;
|
||||||
condition_variable transitionCv;
|
std::condition_variable transitionCv;
|
||||||
bool startAtLaunch = false;
|
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
|
bool verbose = false;
|
||||||
|
bool tansitionOverrideOverride = false;
|
||||||
|
|
||||||
int interval = DEFAULT_INTERVAL;
|
int interval = default_interval;
|
||||||
|
|
||||||
obs_source_t *waitScene = NULL; //scene during which wait started
|
obs_source_t *waitScene = NULL; //scene during which wait started
|
||||||
OBSWeakSource previousScene = NULL;
|
OBSWeakSource previousScene = NULL;
|
||||||
@@ -271,56 +390,84 @@ struct SwitcherData {
|
|||||||
OBSWeakSource lastRandomScene;
|
OBSWeakSource lastRandomScene;
|
||||||
OBSWeakSource nonMatchingScene;
|
OBSWeakSource nonMatchingScene;
|
||||||
NoMatch switchIfNotMatching = NO_SWITCH;
|
NoMatch switchIfNotMatching = NO_SWITCH;
|
||||||
|
StartupBehavior startupBehavior = PERSIST;
|
||||||
|
|
||||||
vector<WindowSceneSwitch> windowSwitches;
|
std::vector<WindowSceneSwitch> windowSwitches;
|
||||||
vector<string> ignoreIdleWindows;
|
std::vector<std::string> ignoreIdleWindows;
|
||||||
string lastTitle;
|
std::string lastTitle;
|
||||||
|
|
||||||
vector<ScreenRegionSwitch> screenRegionSwitches;
|
std::vector<ScreenRegionSwitch> screenRegionSwitches;
|
||||||
|
|
||||||
vector<OBSWeakSource> pauseScenesSwitches;
|
std::vector<OBSWeakSource> pauseScenesSwitches;
|
||||||
|
|
||||||
vector<string> pauseWindowsSwitches;
|
std::vector<std::string> pauseWindowsSwitches;
|
||||||
|
|
||||||
vector<string> ignoreWindowsSwitches;
|
std::vector<std::string> ignoreWindowsSwitches;
|
||||||
|
|
||||||
vector<SceneRoundTripSwitch> sceneRoundTripSwitches;
|
std::vector<SceneRoundTripSwitch> sceneRoundTripSwitches;
|
||||||
|
int sceneRoundTripUnitMultiplier = 1;
|
||||||
|
|
||||||
vector<RandomSwitch> randomSwitches;
|
std::vector<RandomSwitch> randomSwitches;
|
||||||
|
|
||||||
FileIOData fileIO;
|
FileIOData fileIO;
|
||||||
IdleData idleData;
|
IdleData idleData;
|
||||||
vector<FileSwitch> fileSwitches;
|
std::vector<FileSwitch> fileSwitches;
|
||||||
|
CURL *curl = nullptr;
|
||||||
|
|
||||||
vector<ExecutableSceneSwitch> executableSwitches;
|
std::vector<ExecutableSceneSwitch> executableSwitches;
|
||||||
|
|
||||||
bool autoStopEnable = false;
|
bool autoStopEnable = false;
|
||||||
OBSWeakSource autoStopScene;
|
OBSWeakSource autoStopScene;
|
||||||
|
|
||||||
vector<SceneTransition> sceneTransitions;
|
bool autoStartEnable = false;
|
||||||
vector<DefaultSceneTransition> defaultSceneTransitions;
|
AutoStartType autoStartType = RECORDING;
|
||||||
|
OBSWeakSource autoStartScene;
|
||||||
|
bool autoStartedRecently = false;
|
||||||
|
|
||||||
vector<MediaSwitch> mediaSwitches;
|
std::vector<SceneTransition> sceneTransitions;
|
||||||
|
std::vector<DefaultSceneTransition> defaultSceneTransitions;
|
||||||
|
|
||||||
vector<TimeSwitch> timeSwitches;
|
std::vector<MediaSwitch> mediaSwitches;
|
||||||
|
|
||||||
vector<int> functionNamesByPriority = vector<int>{
|
std::vector<TimeSwitch> timeSwitches;
|
||||||
DEFAULT_PRIORITY_0, DEFAULT_PRIORITY_1, DEFAULT_PRIORITY_2,
|
QDateTime liveTime;
|
||||||
DEFAULT_PRIORITY_3, DEFAULT_PRIORITY_4, DEFAULT_PRIORITY_5,
|
|
||||||
DEFAULT_PRIORITY_6, DEFAULT_PRIORITY_7};
|
|
||||||
|
|
||||||
std::vector<std::string> threadPrioritiesNamesOrderdByPrio{
|
std::vector<AudioSwitch> audioSwitches;
|
||||||
"Lowest", "Low", "Normal", "High", "Highest", "Time critical",
|
|
||||||
|
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};
|
||||||
|
|
||||||
|
struct ThreadPrio {
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
uint32_t value;
|
||||||
};
|
};
|
||||||
std::map<std::string, int> threadPriorities = {
|
|
||||||
{"Lowest", QThread::LowestPriority},
|
std::vector<ThreadPrio> threadPriorities{
|
||||||
{"Low", QThread::LowPriority},
|
{"Idle",
|
||||||
{"Normal", QThread::NormalPriority},
|
"scheduled only when no other threads are running (lowest CPU load)",
|
||||||
{"High", QThread::HighPriority},
|
QThread::IdlePriority},
|
||||||
{"Highest", QThread::HighestPriority},
|
{"Lowest", "scheduled less often than LowPriority",
|
||||||
{"Time critical", QThread::TimeCriticalPriority},
|
QThread::LowestPriority},
|
||||||
|
{"Low", "scheduled less often than NormalPriority",
|
||||||
|
QThread::LowPriority},
|
||||||
|
{"Normal", "the default priority of the operating system",
|
||||||
|
QThread::NormalPriority},
|
||||||
|
{"High", "scheduled more often than NormalPriority",
|
||||||
|
QThread::HighPriority},
|
||||||
|
{"Highest", "scheduled more often than HighPriority",
|
||||||
|
QThread::HighestPriority},
|
||||||
|
{"Time critical",
|
||||||
|
"scheduled as often as possible (highest CPU load)",
|
||||||
|
QThread::TimeCriticalPriority},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint32_t threadPriority = QThread::NormalPriority;
|
||||||
|
|
||||||
|
std::vector<int> tabOrder;
|
||||||
|
|
||||||
void Thread();
|
void Thread();
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
@@ -330,10 +477,11 @@ struct SwitcherData {
|
|||||||
void writeSceneInfoToFile();
|
void writeSceneInfoToFile();
|
||||||
void setDefaultSceneTransitions();
|
void setDefaultSceneTransitions();
|
||||||
void autoStopStreamAndRecording();
|
void autoStopStreamAndRecording();
|
||||||
|
void autoStartStreamRecording();
|
||||||
bool checkPause();
|
bool checkPause();
|
||||||
void checkSceneRoundTrip(bool &match, OBSWeakSource &scene,
|
void checkSceneRoundTrip(bool &match, OBSWeakSource &scene,
|
||||||
OBSWeakSource &transition,
|
OBSWeakSource &transition,
|
||||||
unique_lock<mutex> &lock);
|
std::unique_lock<std::mutex> &lock);
|
||||||
void checkIdleSwitch(bool &match, OBSWeakSource &scene,
|
void checkIdleSwitch(bool &match, OBSWeakSource &scene,
|
||||||
OBSWeakSource &transition);
|
OBSWeakSource &transition);
|
||||||
void checkWindowTitleSwitch(bool &match, OBSWeakSource &scene,
|
void checkWindowTitleSwitch(bool &match, OBSWeakSource &scene,
|
||||||
@@ -352,6 +500,36 @@ struct SwitcherData {
|
|||||||
OBSWeakSource &transition);
|
OBSWeakSource &transition);
|
||||||
void checkTimeSwitch(bool &match, OBSWeakSource &scene,
|
void checkTimeSwitch(bool &match, OBSWeakSource &scene,
|
||||||
OBSWeakSource &transition);
|
OBSWeakSource &transition);
|
||||||
|
void checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition);
|
||||||
|
|
||||||
|
void saveWindowTitleSwitches(obs_data_t *obj);
|
||||||
|
void saveScreenRegionSwitches(obs_data_t *obj);
|
||||||
|
void savePauseSwitches(obs_data_t *obj);
|
||||||
|
void saveSceneRoundTripSwitches(obs_data_t *obj);
|
||||||
|
void saveSceneTransitions(obs_data_t *obj);
|
||||||
|
void saveIdleSwitches(obs_data_t *obj);
|
||||||
|
void saveExecutableSwitches(obs_data_t *obj);
|
||||||
|
void saveRandomSwitches(obs_data_t *obj);
|
||||||
|
void saveFileSwitches(obs_data_t *obj);
|
||||||
|
void saveMediaSwitches(obs_data_t *obj);
|
||||||
|
void saveTimeSwitches(obs_data_t *obj);
|
||||||
|
void saveAudioSwitches(obs_data_t *obj);
|
||||||
|
void saveGeneralSettings(obs_data_t *obj);
|
||||||
|
|
||||||
|
void loadWindowTitleSwitches(obs_data_t *obj);
|
||||||
|
void loadScreenRegionSwitches(obs_data_t *obj);
|
||||||
|
void loadPauseSwitches(obs_data_t *obj);
|
||||||
|
void loadSceneRoundTripSwitches(obs_data_t *obj);
|
||||||
|
void loadSceneTransitions(obs_data_t *obj);
|
||||||
|
void loadIdleSwitches(obs_data_t *obj);
|
||||||
|
void loadExecutableSwitches(obs_data_t *obj);
|
||||||
|
void loadRandomSwitches(obs_data_t *obj);
|
||||||
|
void loadFileSwitches(obs_data_t *obj);
|
||||||
|
void loadMediaSwitches(obs_data_t *obj);
|
||||||
|
void loadTimeSwitches(obs_data_t *obj);
|
||||||
|
void loadAudioSwitches(obs_data_t *obj);
|
||||||
|
void loadGeneralSettings(obs_data_t *obj);
|
||||||
|
|
||||||
void Prune()
|
void Prune()
|
||||||
{
|
{
|
||||||
@@ -440,7 +618,8 @@ struct SwitcherData {
|
|||||||
|
|
||||||
for (size_t i = 0; i < timeSwitches.size(); i++) {
|
for (size_t i = 0; i < timeSwitches.size(); i++) {
|
||||||
TimeSwitch &s = timeSwitches[i];
|
TimeSwitch &s = timeSwitches[i];
|
||||||
if (!WeakSourceValid(s.scene) ||
|
if ((!s.usePreviousScene &&
|
||||||
|
!WeakSourceValid(s.scene)) ||
|
||||||
!WeakSourceValid(s.transition))
|
!WeakSourceValid(s.transition))
|
||||||
timeSwitches.erase(timeSwitches.begin() + i--);
|
timeSwitches.erase(timeSwitches.begin() + i--);
|
||||||
}
|
}
|
||||||
@@ -450,6 +629,32 @@ struct SwitcherData {
|
|||||||
!WeakSourceValid(idleData.transition)) {
|
!WeakSourceValid(idleData.transition)) {
|
||||||
idleData.idleEnable = false;
|
idleData.idleEnable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mediaSwitches.size(); i++) {
|
||||||
|
MediaSwitch &s = mediaSwitches[i];
|
||||||
|
if ((!s.usePreviousScene &&
|
||||||
|
!WeakSourceValid(s.scene)) ||
|
||||||
|
!WeakSourceValid(s.source) ||
|
||||||
|
!WeakSourceValid(s.transition))
|
||||||
|
mediaSwitches.erase(mediaSwitches.begin() +
|
||||||
|
i--);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < audioSwitches.size(); i++) {
|
||||||
|
AudioSwitch &s = audioSwitches[i];
|
||||||
|
if ((!s.usePreviousScene &&
|
||||||
|
!WeakSourceValid(s.scene)) ||
|
||||||
|
!WeakSourceValid(s.transition))
|
||||||
|
audioSwitches.erase(audioSwitches.begin() +
|
||||||
|
i--);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inline ~SwitcherData() { Stop(); }
|
inline ~SwitcherData() { Stop(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern SwitcherData *switcher;
|
||||||
|
class SwitcherThread : public QThread {
|
||||||
|
public:
|
||||||
|
explicit SwitcherThread(){};
|
||||||
|
void run() { switcher->Thread(); };
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <obs-frontend-api.h>
|
#include <obs-frontend-api.h>
|
||||||
#include "switcher-data-structs.hpp"
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static inline bool WeakSourceValid(obs_weak_source_t *ws)
|
static inline bool WeakSourceValid(obs_weak_source_t *ws)
|
||||||
{
|
{
|
||||||
@@ -14,14 +12,26 @@ static inline bool WeakSourceValid(obs_weak_source_t *ws)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline QString MakeSwitchName(const QString &scene, const QString &value,
|
static inline QString MakeSwitchName(const QString &scene, const QString &value,
|
||||||
const QString &transition, bool fullscreen)
|
const QString &transition, bool fullscreen,
|
||||||
|
bool focus)
|
||||||
{
|
{
|
||||||
if (!fullscreen)
|
QString name = QStringLiteral("[") + scene + QStringLiteral(", ") +
|
||||||
return QStringLiteral("[") + scene + QStringLiteral(", ") +
|
|
||||||
transition + QStringLiteral("]: ") + value;
|
transition + QStringLiteral("]: ") + value;
|
||||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition +
|
|
||||||
QStringLiteral("]: ") + value +
|
if (fullscreen || focus) {
|
||||||
QStringLiteral(" (only if window is fullscreen)");
|
name += QStringLiteral(" (only if");
|
||||||
|
|
||||||
|
if (fullscreen)
|
||||||
|
name += QStringLiteral(" fullscreen");
|
||||||
|
if (fullscreen && focus)
|
||||||
|
name += QStringLiteral(" and");
|
||||||
|
if (focus)
|
||||||
|
name += QStringLiteral(" focused");
|
||||||
|
|
||||||
|
name += QStringLiteral(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QString MakeSwitchNameExecutable(const QString &scene,
|
static inline QString MakeSwitchNameExecutable(const QString &scene,
|
||||||
@@ -34,7 +44,7 @@ static inline QString MakeSwitchNameExecutable(const QString &scene,
|
|||||||
transition + QStringLiteral("]: ") + value;
|
transition + QStringLiteral("]: ") + value;
|
||||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition +
|
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition +
|
||||||
QStringLiteral("]: ") + value +
|
QStringLiteral("]: ") + value +
|
||||||
QStringLiteral(" (only if window is focused)");
|
QStringLiteral(" (only if focused)");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QString MakeScreenRegionSwitchName(const QString &scene,
|
static inline QString MakeScreenRegionSwitchName(const QString &scene,
|
||||||
@@ -159,18 +169,77 @@ MakeMediaSwitchName(const QString &source, const QString &scene,
|
|||||||
return switchName;
|
return switchName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ANY_DAY = 0,
|
||||||
|
MONDAY = 1,
|
||||||
|
TUSEDAY = 2,
|
||||||
|
WEDNESDAY = 3,
|
||||||
|
THURSDAY = 4,
|
||||||
|
FRIDAY = 5,
|
||||||
|
SATURDAY = 6,
|
||||||
|
SUNDAY = 7,
|
||||||
|
LIVE = 8
|
||||||
|
} timeTrigger;
|
||||||
|
|
||||||
static inline QString MakeTimeSwitchName(const QString &scene,
|
static inline QString MakeTimeSwitchName(const QString &scene,
|
||||||
const QString &transition, QTime &time)
|
const QString &transition,
|
||||||
|
const timeTrigger &trigger,
|
||||||
|
const QTime &time)
|
||||||
{
|
{
|
||||||
QString switchName = QStringLiteral("At ") + time.toString() +
|
QString switchName;
|
||||||
QStringLiteral(" switch to ") + scene +
|
|
||||||
|
switch (trigger) {
|
||||||
|
case ANY_DAY:
|
||||||
|
switchName = QStringLiteral("On any weekday");
|
||||||
|
break;
|
||||||
|
case MONDAY:
|
||||||
|
switchName = QStringLiteral("Mondays");
|
||||||
|
break;
|
||||||
|
case TUSEDAY:
|
||||||
|
switchName = QStringLiteral("Tusedays");
|
||||||
|
break;
|
||||||
|
case WEDNESDAY:
|
||||||
|
switchName = QStringLiteral("Wednesdays");
|
||||||
|
break;
|
||||||
|
case THURSDAY:
|
||||||
|
switchName = QStringLiteral("Thursdays");
|
||||||
|
break;
|
||||||
|
case FRIDAY:
|
||||||
|
switchName = QStringLiteral("Fridays");
|
||||||
|
break;
|
||||||
|
case SATURDAY:
|
||||||
|
switchName = QStringLiteral("Saturdays");
|
||||||
|
break;
|
||||||
|
case SUNDAY:
|
||||||
|
switchName = QStringLiteral("Sundays");
|
||||||
|
break;
|
||||||
|
case LIVE:
|
||||||
|
switchName = QStringLiteral(
|
||||||
|
"Relative to starting streaming / recording");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switchName += QStringLiteral(" at ") + time.toString() +
|
||||||
|
QStringLiteral(" switch to ") + scene +
|
||||||
|
QStringLiteral(" using ") + transition;
|
||||||
|
return switchName;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QString MakeAudioSwitchName(const QString &scene,
|
||||||
|
const QString &transition,
|
||||||
|
const QString &audioSrouce,
|
||||||
|
const int &volume)
|
||||||
|
{
|
||||||
|
QString switchName = QStringLiteral("When volume of ") + audioSrouce +
|
||||||
|
QStringLiteral(" is above ") +
|
||||||
|
QString::number(volume) +
|
||||||
|
QStringLiteral("% switch to ") + scene +
|
||||||
QStringLiteral(" using ") + transition;
|
QStringLiteral(" using ") + transition;
|
||||||
return switchName;
|
return switchName;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline string GetWeakSourceName(obs_weak_source_t *weak_source)
|
static inline std::string GetWeakSourceName(obs_weak_source_t *weak_source)
|
||||||
{
|
{
|
||||||
string name;
|
std::string name;
|
||||||
|
|
||||||
obs_source_t *source = obs_weak_source_get_source(weak_source);
|
obs_source_t *source = obs_weak_source_get_source(weak_source);
|
||||||
if (source) {
|
if (source) {
|
||||||
|
|||||||
245
src/headers/volume-control.hpp
Normal file
245
src/headers/volume-control.hpp
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
class VolumeMeterTimer;
|
||||||
|
|
||||||
|
class VolumeMeter : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QColor backgroundNominalColor READ getBackgroundNominalColor
|
||||||
|
WRITE setBackgroundNominalColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor backgroundWarningColor READ getBackgroundWarningColor
|
||||||
|
WRITE setBackgroundWarningColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor backgroundErrorColor READ getBackgroundErrorColor
|
||||||
|
WRITE setBackgroundErrorColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor foregroundNominalColor READ getForegroundNominalColor
|
||||||
|
WRITE setForegroundNominalColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor foregroundWarningColor READ getForegroundWarningColor
|
||||||
|
WRITE setForegroundWarningColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor foregroundErrorColor READ getForegroundErrorColor
|
||||||
|
WRITE setForegroundErrorColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor clipColor READ getClipColor WRITE setClipColor
|
||||||
|
DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor magnitudeColor READ getMagnitudeColor WRITE
|
||||||
|
setMagnitudeColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor majorTickColor READ getMajorTickColor WRITE
|
||||||
|
setMajorTickColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor minorTickColor READ getMinorTickColor WRITE
|
||||||
|
setMinorTickColor DESIGNABLE true)
|
||||||
|
|
||||||
|
// Levels are denoted in dBFS.
|
||||||
|
Q_PROPERTY(qreal minimumLevel READ getMinimumLevel WRITE setMinimumLevel
|
||||||
|
DESIGNABLE true)
|
||||||
|
Q_PROPERTY(qreal warningLevel READ getWarningLevel WRITE setWarningLevel
|
||||||
|
DESIGNABLE true)
|
||||||
|
Q_PROPERTY(qreal errorLevel READ getErrorLevel WRITE setErrorLevel
|
||||||
|
DESIGNABLE true)
|
||||||
|
Q_PROPERTY(qreal clipLevel READ getClipLevel WRITE setClipLevel
|
||||||
|
DESIGNABLE true)
|
||||||
|
Q_PROPERTY(qreal minimumInputLevel READ getMinimumInputLevel WRITE
|
||||||
|
setMinimumInputLevel DESIGNABLE true)
|
||||||
|
|
||||||
|
// Rates are denoted in dB/second.
|
||||||
|
Q_PROPERTY(qreal peakDecayRate READ getPeakDecayRate WRITE
|
||||||
|
setPeakDecayRate DESIGNABLE true)
|
||||||
|
|
||||||
|
// Time in seconds for the VU meter to integrate over.
|
||||||
|
Q_PROPERTY(
|
||||||
|
qreal magnitudeIntegrationTime READ getMagnitudeIntegrationTime
|
||||||
|
WRITE setMagnitudeIntegrationTime DESIGNABLE true)
|
||||||
|
|
||||||
|
// Duration is denoted in seconds.
|
||||||
|
Q_PROPERTY(qreal peakHoldDuration READ getPeakHoldDuration WRITE
|
||||||
|
setPeakHoldDuration DESIGNABLE true)
|
||||||
|
Q_PROPERTY(qreal inputPeakHoldDuration READ getInputPeakHoldDuration
|
||||||
|
WRITE setInputPeakHoldDuration DESIGNABLE true)
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void ClipEnding();
|
||||||
|
|
||||||
|
private:
|
||||||
|
obs_volmeter_t *obs_volmeter;
|
||||||
|
static QWeakPointer<VolumeMeterTimer> updateTimer;
|
||||||
|
QSharedPointer<VolumeMeterTimer> updateTimerRef;
|
||||||
|
|
||||||
|
inline void resetLevels();
|
||||||
|
inline void handleChannelCofigurationChange();
|
||||||
|
inline bool detectIdle(uint64_t ts);
|
||||||
|
inline void calculateBallistics(uint64_t ts,
|
||||||
|
qreal timeSinceLastRedraw = 0.0);
|
||||||
|
inline void calculateBallisticsForChannel(int channelNr, uint64_t ts,
|
||||||
|
qreal timeSinceLastRedraw);
|
||||||
|
|
||||||
|
void paintInputMeter(QPainter &painter, int x, int y, int width,
|
||||||
|
int height, float peakHold);
|
||||||
|
void paintHMeter(QPainter &painter, int x, int y, int width, int height,
|
||||||
|
float magnitude, float peak, float peakHold);
|
||||||
|
void paintHTicks(QPainter &painter, int x, int y, int width,
|
||||||
|
int height);
|
||||||
|
void paintVMeter(QPainter &painter, int x, int y, int width, int height,
|
||||||
|
float magnitude, float peak, float peakHold);
|
||||||
|
void paintVTicks(QPainter &painter, int x, int y, int height);
|
||||||
|
|
||||||
|
QMutex dataMutex;
|
||||||
|
|
||||||
|
uint64_t currentLastUpdateTime = 0;
|
||||||
|
float currentMagnitude[MAX_AUDIO_CHANNELS];
|
||||||
|
float currentPeak[MAX_AUDIO_CHANNELS];
|
||||||
|
float currentInputPeak[MAX_AUDIO_CHANNELS];
|
||||||
|
|
||||||
|
QPixmap *tickPaintCache = nullptr;
|
||||||
|
int displayNrAudioChannels = 0;
|
||||||
|
float displayMagnitude[MAX_AUDIO_CHANNELS];
|
||||||
|
float displayPeak[MAX_AUDIO_CHANNELS];
|
||||||
|
float displayPeakHold[MAX_AUDIO_CHANNELS];
|
||||||
|
uint64_t displayPeakHoldLastUpdateTime[MAX_AUDIO_CHANNELS];
|
||||||
|
float displayInputPeakHold[MAX_AUDIO_CHANNELS];
|
||||||
|
uint64_t displayInputPeakHoldLastUpdateTime[MAX_AUDIO_CHANNELS];
|
||||||
|
|
||||||
|
QFont tickFont;
|
||||||
|
QColor backgroundNominalColor;
|
||||||
|
QColor backgroundWarningColor;
|
||||||
|
QColor backgroundErrorColor;
|
||||||
|
QColor foregroundNominalColor;
|
||||||
|
QColor foregroundWarningColor;
|
||||||
|
QColor foregroundErrorColor;
|
||||||
|
QColor clipColor;
|
||||||
|
QColor magnitudeColor;
|
||||||
|
QColor majorTickColor;
|
||||||
|
QColor minorTickColor;
|
||||||
|
qreal minimumLevel;
|
||||||
|
qreal warningLevel;
|
||||||
|
qreal errorLevel;
|
||||||
|
qreal clipLevel;
|
||||||
|
qreal minimumInputLevel;
|
||||||
|
qreal peakDecayRate;
|
||||||
|
qreal magnitudeIntegrationTime;
|
||||||
|
qreal peakHoldDuration;
|
||||||
|
qreal inputPeakHoldDuration;
|
||||||
|
|
||||||
|
uint64_t lastRedrawTime = 0;
|
||||||
|
int channels = 0;
|
||||||
|
bool clipping = false;
|
||||||
|
bool vertical;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit VolumeMeter(QWidget *parent = nullptr,
|
||||||
|
obs_volmeter_t *obs_volmeter = nullptr,
|
||||||
|
bool vertical = false);
|
||||||
|
~VolumeMeter();
|
||||||
|
|
||||||
|
void setLevels(const float magnitude[MAX_AUDIO_CHANNELS],
|
||||||
|
const float peak[MAX_AUDIO_CHANNELS],
|
||||||
|
const float inputPeak[MAX_AUDIO_CHANNELS]);
|
||||||
|
|
||||||
|
QColor getBackgroundNominalColor() const;
|
||||||
|
void setBackgroundNominalColor(QColor c);
|
||||||
|
QColor getBackgroundWarningColor() const;
|
||||||
|
void setBackgroundWarningColor(QColor c);
|
||||||
|
QColor getBackgroundErrorColor() const;
|
||||||
|
void setBackgroundErrorColor(QColor c);
|
||||||
|
QColor getForegroundNominalColor() const;
|
||||||
|
void setForegroundNominalColor(QColor c);
|
||||||
|
QColor getForegroundWarningColor() const;
|
||||||
|
void setForegroundWarningColor(QColor c);
|
||||||
|
QColor getForegroundErrorColor() const;
|
||||||
|
void setForegroundErrorColor(QColor c);
|
||||||
|
QColor getClipColor() const;
|
||||||
|
void setClipColor(QColor c);
|
||||||
|
QColor getMagnitudeColor() const;
|
||||||
|
void setMagnitudeColor(QColor c);
|
||||||
|
QColor getMajorTickColor() const;
|
||||||
|
void setMajorTickColor(QColor c);
|
||||||
|
QColor getMinorTickColor() const;
|
||||||
|
void setMinorTickColor(QColor c);
|
||||||
|
qreal getMinimumLevel() const;
|
||||||
|
void setMinimumLevel(qreal v);
|
||||||
|
qreal getWarningLevel() const;
|
||||||
|
void setWarningLevel(qreal v);
|
||||||
|
qreal getErrorLevel() const;
|
||||||
|
void setErrorLevel(qreal v);
|
||||||
|
qreal getClipLevel() const;
|
||||||
|
void setClipLevel(qreal v);
|
||||||
|
qreal getMinimumInputLevel() const;
|
||||||
|
void setMinimumInputLevel(qreal v);
|
||||||
|
qreal getPeakDecayRate() const;
|
||||||
|
void setPeakDecayRate(qreal v);
|
||||||
|
qreal getMagnitudeIntegrationTime() const;
|
||||||
|
void setMagnitudeIntegrationTime(qreal v);
|
||||||
|
qreal getPeakHoldDuration() const;
|
||||||
|
void setPeakHoldDuration(qreal v);
|
||||||
|
qreal getInputPeakHoldDuration() const;
|
||||||
|
void setInputPeakHoldDuration(qreal v);
|
||||||
|
void setPeakMeterType(enum obs_peak_meter_type peakMeterType);
|
||||||
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class VolumeMeterTimer : public QTimer {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline VolumeMeterTimer() : QTimer() {}
|
||||||
|
|
||||||
|
void AddVolControl(VolumeMeter *meter);
|
||||||
|
void RemoveVolControl(VolumeMeter *meter);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
QList<VolumeMeter *> volumeMeters;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QSlider;
|
||||||
|
class MuteCheckBox;
|
||||||
|
|
||||||
|
class VolControl : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
OBSSource source;
|
||||||
|
QLabel *nameLabel;
|
||||||
|
QLabel *volLabel;
|
||||||
|
VolumeMeter *volMeter;
|
||||||
|
QSlider *slider;
|
||||||
|
float levelTotal;
|
||||||
|
float levelCount;
|
||||||
|
obs_fader_t *obs_fader;
|
||||||
|
obs_volmeter_t *obs_volmeter;
|
||||||
|
bool vertical;
|
||||||
|
|
||||||
|
static void OBSVolumeChanged(void *param, float db);
|
||||||
|
static void OBSVolumeLevel(void *data,
|
||||||
|
const float magnitude[MAX_AUDIO_CHANNELS],
|
||||||
|
const float peak[MAX_AUDIO_CHANNELS],
|
||||||
|
const float inputPeak[MAX_AUDIO_CHANNELS]);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void SliderChanged(int vol);
|
||||||
|
void updateText();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit VolControl(OBSSource source, bool vertical = false);
|
||||||
|
~VolControl();
|
||||||
|
|
||||||
|
inline obs_source_t *GetSource() const { return source; }
|
||||||
|
|
||||||
|
QString GetName() const;
|
||||||
|
void SetName(const QString &newName);
|
||||||
|
|
||||||
|
void SetMeterDecayRate(qreal q);
|
||||||
|
void setPeakMeterType(enum obs_peak_meter_type peakMeterType);
|
||||||
|
|
||||||
|
void EnableSlider(bool enable);
|
||||||
|
|
||||||
|
QSlider *GetSlider() const;
|
||||||
|
};
|
||||||
124
src/hotkey.cpp
124
src/hotkey.cpp
@@ -1,31 +1,30 @@
|
|||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
void startHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pressed)
|
void startHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
|
||||||
|
bool pressed)
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER(data);
|
UNUSED_PARAMETER(data);
|
||||||
UNUSED_PARAMETER(hotkey);
|
UNUSED_PARAMETER(hotkey);
|
||||||
|
|
||||||
if (pressed)
|
if (pressed) {
|
||||||
{
|
if (!(switcher->th && switcher->th->isRunning()))
|
||||||
if (!switcher->th.joinable())
|
|
||||||
switcher->Start();
|
switcher->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_data_array* hotkeyData = obs_hotkey_save(id);
|
obs_data_array *hotkeyData = obs_hotkey_save(id);
|
||||||
|
|
||||||
if (hotkeyData != NULL)
|
if (hotkeyData != NULL) {
|
||||||
{
|
char *path = obs_module_config_path("");
|
||||||
char* path = obs_module_config_path("");
|
std::ofstream file;
|
||||||
ofstream file;
|
file.open(std::string(path).append(start_hotkey_path),
|
||||||
file.open(string(path).append(START_HOTKEY_PATH), ofstream::trunc);
|
std::ofstream::trunc);
|
||||||
if (file.is_open())
|
if (file.is_open()) {
|
||||||
{
|
|
||||||
size_t num = obs_data_array_count(hotkeyData);
|
size_t num = obs_data_array_count(hotkeyData);
|
||||||
for (size_t i = 0; i < num; i++)
|
for (size_t i = 0; i < num; i++) {
|
||||||
{
|
obs_data_t *data =
|
||||||
obs_data_t* data = obs_data_array_item(hotkeyData, i);
|
obs_data_array_item(hotkeyData, i);
|
||||||
string temp = obs_data_get_json(data);
|
std::string temp = obs_data_get_json(data);
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
file << temp;
|
file << temp;
|
||||||
}
|
}
|
||||||
@@ -36,31 +35,30 @@ void startHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pr
|
|||||||
obs_data_array_release(hotkeyData);
|
obs_data_array_release(hotkeyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pressed)
|
void stopHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
|
||||||
|
bool pressed)
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER(data);
|
UNUSED_PARAMETER(data);
|
||||||
UNUSED_PARAMETER(hotkey);
|
UNUSED_PARAMETER(hotkey);
|
||||||
|
|
||||||
if (pressed)
|
if (pressed) {
|
||||||
{
|
if (switcher->th && switcher->th->isRunning())
|
||||||
if (switcher->th.joinable())
|
|
||||||
switcher->Stop();
|
switcher->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_data_array* hotkeyData = obs_hotkey_save(id);
|
obs_data_array *hotkeyData = obs_hotkey_save(id);
|
||||||
|
|
||||||
if (hotkeyData != NULL)
|
if (hotkeyData != NULL) {
|
||||||
{
|
char *path = obs_module_config_path("");
|
||||||
char* path = obs_module_config_path("");
|
std::ofstream file;
|
||||||
ofstream file;
|
file.open(std::string(path).append(stop_hotkey_path),
|
||||||
file.open(string(path).append(STOP_HOTKEY_PATH), ofstream::trunc);
|
std::ofstream::trunc);
|
||||||
if (file.is_open())
|
if (file.is_open()) {
|
||||||
{
|
|
||||||
size_t num = obs_data_array_count(hotkeyData);
|
size_t num = obs_data_array_count(hotkeyData);
|
||||||
for (size_t i = 0; i < num; i++)
|
for (size_t i = 0; i < num; i++) {
|
||||||
{
|
obs_data_t *data =
|
||||||
obs_data_t* data = obs_data_array_item(hotkeyData, i);
|
obs_data_array_item(hotkeyData, i);
|
||||||
string temp = obs_data_get_json(data);
|
std::string temp = obs_data_get_json(data);
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
file << temp;
|
file << temp;
|
||||||
}
|
}
|
||||||
@@ -71,33 +69,32 @@ void stopHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pre
|
|||||||
obs_data_array_release(hotkeyData);
|
obs_data_array_release(hotkeyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startStopToggleHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pressed)
|
void startStopToggleHotkeyFunc(void *data, obs_hotkey_id id,
|
||||||
|
obs_hotkey_t *hotkey, bool pressed)
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER(data);
|
UNUSED_PARAMETER(data);
|
||||||
UNUSED_PARAMETER(hotkey);
|
UNUSED_PARAMETER(hotkey);
|
||||||
|
|
||||||
if (pressed)
|
if (pressed) {
|
||||||
{
|
if (switcher->th && switcher->th->isRunning())
|
||||||
if (switcher->th.joinable())
|
|
||||||
switcher->Stop();
|
switcher->Stop();
|
||||||
else
|
else
|
||||||
switcher->Start();
|
switcher->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_data_array* hotkeyData = obs_hotkey_save(id);
|
obs_data_array *hotkeyData = obs_hotkey_save(id);
|
||||||
|
|
||||||
if (hotkeyData != NULL)
|
if (hotkeyData != NULL) {
|
||||||
{
|
char *path = obs_module_config_path("");
|
||||||
char* path = obs_module_config_path("");
|
std::ofstream file;
|
||||||
ofstream file;
|
file.open(std::string(path).append(toggle_hotkey_path),
|
||||||
file.open(string(path).append(TOGGLE_HOTKEY_PATH), ofstream::trunc);
|
std::ofstream::trunc);
|
||||||
if (file.is_open())
|
if (file.is_open()) {
|
||||||
{
|
|
||||||
size_t num = obs_data_array_count(hotkeyData);
|
size_t num = obs_data_array_count(hotkeyData);
|
||||||
for (size_t i = 0; i < num; i++)
|
for (size_t i = 0; i < num; i++) {
|
||||||
{
|
obs_data_t *data =
|
||||||
obs_data_t* data = obs_data_array_item(hotkeyData, i);
|
obs_data_array_item(hotkeyData, i);
|
||||||
string temp = obs_data_get_json(data);
|
std::string temp = obs_data_get_json(data);
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
file << temp;
|
file << temp;
|
||||||
}
|
}
|
||||||
@@ -108,32 +105,31 @@ void startStopToggleHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotke
|
|||||||
obs_data_array_release(hotkeyData);
|
obs_data_array_release(hotkeyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
string loadConfigFile(string filename)
|
std::string loadConfigFile(std::string filename)
|
||||||
{
|
{
|
||||||
ifstream settingsFile;
|
std::ifstream settingsFile;
|
||||||
char* path = obs_module_config_path("");
|
char *path = obs_module_config_path("");
|
||||||
string value;
|
std::string value;
|
||||||
|
|
||||||
settingsFile.open(string(path).append(filename));
|
settingsFile.open(std::string(path).append(filename));
|
||||||
if (settingsFile.is_open())
|
if (settingsFile.is_open()) {
|
||||||
{
|
settingsFile.seekg(0, std::ios::end);
|
||||||
settingsFile.seekg(0, ios::end);
|
|
||||||
value.reserve(settingsFile.tellg());
|
value.reserve(settingsFile.tellg());
|
||||||
settingsFile.seekg(0, ios::beg);
|
settingsFile.seekg(0, std::ios::beg);
|
||||||
value.assign((istreambuf_iterator<char>(settingsFile)), istreambuf_iterator<char>());
|
value.assign((std::istreambuf_iterator<char>(settingsFile)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
settingsFile.close();
|
settingsFile.close();
|
||||||
}
|
}
|
||||||
bfree(path);
|
bfree(path);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadKeybinding(obs_hotkey_id hotkeyId, string path)
|
void loadKeybinding(obs_hotkey_id hotkeyId, std::string path)
|
||||||
{
|
{
|
||||||
string bindings = loadConfigFile(path);
|
std::string bindings = loadConfigFile(path);
|
||||||
if (!bindings.empty())
|
if (!bindings.empty()) {
|
||||||
{
|
obs_data_array_t *hotkeyData = obs_data_array_create();
|
||||||
obs_data_array_t* hotkeyData = obs_data_array_create();
|
obs_data_t *data = obs_data_create_from_json(bindings.c_str());
|
||||||
obs_data_t* data = obs_data_create_from_json(bindings.c_str());
|
|
||||||
obs_data_array_insert(hotkeyData, 0, data);
|
obs_data_array_insert(hotkeyData, 0, data);
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
obs_hotkey_load(hotkeyId, hotkeyData);
|
obs_hotkey_load(hotkeyId, hotkeyData);
|
||||||
|
|||||||
@@ -1,54 +1,50 @@
|
|||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
void SwitcherData::checkIdleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
void SwitcherData::checkIdleSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
if (!idleData.idleEnable)
|
if (!idleData.idleEnable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string title;
|
std::string title;
|
||||||
bool ignoreIdle = false;
|
bool ignoreIdle = false;
|
||||||
//lock.unlock();
|
//lock.unlock();
|
||||||
GetCurrentWindowTitle(title);
|
GetCurrentWindowTitle(title);
|
||||||
//lock.lock();
|
//lock.lock();
|
||||||
|
|
||||||
for (string& window : ignoreIdleWindows)
|
for (std::string &window : ignoreIdleWindows) {
|
||||||
{
|
if (window == title) {
|
||||||
if (window == title)
|
|
||||||
{
|
|
||||||
ignoreIdle = true;
|
ignoreIdle = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ignoreIdle)
|
if (!ignoreIdle) {
|
||||||
{
|
for (std::string &window : ignoreIdleWindows) {
|
||||||
for (string& window : ignoreIdleWindows)
|
try {
|
||||||
{
|
bool matches = std::regex_match(
|
||||||
try
|
title, std::regex(window));
|
||||||
{
|
if (matches) {
|
||||||
bool matches = regex_match(title, regex(window));
|
|
||||||
if (matches)
|
|
||||||
{
|
|
||||||
ignoreIdle = true;
|
ignoreIdle = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} catch (const std::regex_error &) {
|
||||||
catch (const regex_error&)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ignoreIdle && secondsSinceLastInput() > idleData.time)
|
if (!ignoreIdle && secondsSinceLastInput() > idleData.time) {
|
||||||
{
|
|
||||||
if (idleData.alreadySwitched)
|
if (idleData.alreadySwitched)
|
||||||
return;
|
return;
|
||||||
scene = (idleData.usePreviousScene) ? previousScene : idleData.scene;
|
scene = (idleData.usePreviousScene) ? previousScene
|
||||||
|
: idleData.scene;
|
||||||
transition = idleData.transition;
|
transition = idleData.transition;
|
||||||
match = true;
|
match = true;
|
||||||
idleData.alreadySwitched = true;
|
idleData.alreadySwitched = true;
|
||||||
}
|
|
||||||
else
|
if (verbose)
|
||||||
|
blog(LOG_INFO, "Advanced Scene Switcher idle match");
|
||||||
|
} else
|
||||||
idleData.alreadySwitched = false;
|
idleData.alreadySwitched = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,17 +53,14 @@ void SceneSwitcher::on_idleCheckBox_stateChanged(int state)
|
|||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
if (!state)
|
if (!state) {
|
||||||
{
|
|
||||||
ui->idleScenes->setDisabled(true);
|
ui->idleScenes->setDisabled(true);
|
||||||
ui->idleSpinBox->setDisabled(true);
|
ui->idleSpinBox->setDisabled(true);
|
||||||
ui->idleTransitions->setDisabled(true);
|
ui->idleTransitions->setDisabled(true);
|
||||||
|
|
||||||
switcher->idleData.idleEnable = false;
|
switcher->idleData.idleEnable = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->idleScenes->setDisabled(false);
|
ui->idleScenes->setDisabled(false);
|
||||||
ui->idleSpinBox->setDisabled(false);
|
ui->idleSpinBox->setDisabled(false);
|
||||||
ui->idleTransitions->setDisabled(false);
|
ui->idleTransitions->setDisabled(false);
|
||||||
@@ -79,18 +72,17 @@ void SceneSwitcher::on_idleCheckBox_stateChanged(int state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::UpdateIdleDataTransition(const QString &name)
|
||||||
void SceneSwitcher::UpdateIdleDataTransition(const QString& name)
|
|
||||||
{
|
{
|
||||||
obs_weak_source_t* transition = GetWeakTransitionByQString(name);
|
obs_weak_source_t *transition = GetWeakTransitionByQString(name);
|
||||||
switcher->idleData.transition = transition;
|
switcher->idleData.transition = transition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::UpdateIdleDataScene(const QString& name)
|
void SceneSwitcher::UpdateIdleDataScene(const QString &name)
|
||||||
{
|
{
|
||||||
switcher->idleData.usePreviousScene = (name == PREVIOUS_SCENE_NAME);
|
switcher->idleData.usePreviousScene = (name == previous_scene_name);
|
||||||
obs_source_t* scene = obs_get_source_by_name(name.toUtf8().constData());
|
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(scene);
|
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
|
||||||
|
|
||||||
switcher->idleData.scene = ws;
|
switcher->idleData.scene = ws;
|
||||||
|
|
||||||
@@ -98,21 +90,21 @@ void SceneSwitcher::UpdateIdleDataScene(const QString& name)
|
|||||||
obs_source_release(scene);
|
obs_source_release(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_idleTransitions_currentTextChanged(const QString& text)
|
void SceneSwitcher::on_idleTransitions_currentTextChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
UpdateIdleDataTransition(text);
|
UpdateIdleDataTransition(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_idleScenes_currentTextChanged(const QString& text)
|
void SceneSwitcher::on_idleScenes_currentTextChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
UpdateIdleDataScene(text);
|
UpdateIdleDataScene(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +112,7 @@ void SceneSwitcher::on_idleSpinBox_valueChanged(int i)
|
|||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
return;
|
return;
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->idleData.time = i;
|
switcher->idleData.time = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,15 +123,13 @@ void SceneSwitcher::on_ignoreIdleWindows_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->ignoreIdleWindows->item(idx);
|
QListWidgetItem *item = ui->ignoreIdleWindows->item(idx);
|
||||||
|
|
||||||
QString window = item->data(Qt::UserRole).toString();
|
QString window = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& w : switcher->ignoreIdleWindows)
|
for (auto &w : switcher->ignoreIdleWindows) {
|
||||||
{
|
if (window.compare(w.c_str()) == 0) {
|
||||||
if (window.compare(w.c_str()) == 0)
|
|
||||||
{
|
|
||||||
ui->ignoreIdleWindowsWindows->setCurrentText(w.c_str());
|
ui->ignoreIdleWindowsWindows->setCurrentText(w.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -155,37 +145,37 @@ void SceneSwitcher::on_ignoreIdleAdd_clicked()
|
|||||||
|
|
||||||
QVariant v = QVariant::fromValue(windowName);
|
QVariant v = QVariant::fromValue(windowName);
|
||||||
|
|
||||||
QList<QListWidgetItem*> items = ui->ignoreIdleWindows->findItems(windowName, Qt::MatchExactly);
|
QList<QListWidgetItem *> items =
|
||||||
|
ui->ignoreIdleWindows->findItems(windowName, Qt::MatchExactly);
|
||||||
|
|
||||||
if (items.size() == 0)
|
if (items.size() == 0) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(windowName, ui->ignoreIdleWindows);
|
new QListWidgetItem(windowName, ui->ignoreIdleWindows);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->ignoreIdleWindows.emplace_back(windowName.toUtf8().constData());
|
switcher->ignoreIdleWindows.emplace_back(
|
||||||
|
windowName.toUtf8().constData());
|
||||||
ui->ignoreIdleWindows->sortItems();
|
ui->ignoreIdleWindows->sortItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_ignoreIdleRemove_clicked()
|
void SceneSwitcher::on_ignoreIdleRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->ignoreIdleWindows->currentItem();
|
QListWidgetItem *item = ui->ignoreIdleWindows->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString windowName = item->data(Qt::UserRole).toString();
|
QString windowName = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& windows = switcher->ignoreIdleWindows;
|
auto &windows = switcher->ignoreIdleWindows;
|
||||||
|
|
||||||
for (auto it = windows.begin(); it != windows.end(); ++it)
|
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s == windowName.toUtf8().constData())
|
if (s == windowName.toUtf8().constData()) {
|
||||||
{
|
|
||||||
windows.erase(it);
|
windows.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -195,18 +185,16 @@ void SceneSwitcher::on_ignoreIdleRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::IgnoreIdleWindowsFindByData(const QString& window)
|
int SceneSwitcher::IgnoreIdleWindowsFindByData(const QString &window)
|
||||||
{
|
{
|
||||||
int count = ui->ignoreIdleWindows->count();
|
int count = ui->ignoreIdleWindows->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->ignoreIdleWindows->item(i);
|
||||||
QListWidgetItem* item = ui->ignoreIdleWindows->item(i);
|
|
||||||
QString itemRegion = item->data(Qt::UserRole).toString();
|
QString itemRegion = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemRegion == window)
|
if (itemRegion == window) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -214,3 +202,96 @@ int SceneSwitcher::IgnoreIdleWindowsFindByData(const QString& window)
|
|||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveIdleSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *ignoreIdleWindowsArray = obs_data_array_create();
|
||||||
|
for (std::string &window : switcher->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);
|
||||||
|
obs_data_release(array_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadIdleSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->ignoreIdleWindows.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *ignoreIdleWindowsArray =
|
||||||
|
obs_data_get_array(obj, "ignoreIdleWindows");
|
||||||
|
size_t count = obs_data_array_count(ignoreIdleWindowsArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(ignoreIdleWindowsArray, i);
|
||||||
|
|
||||||
|
const char *window = obs_data_get_string(array_obj, "window");
|
||||||
|
|
||||||
|
switcher->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupIdleTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->idleScenes, true);
|
||||||
|
populateTransitionSelection(ui->idleTransitions);
|
||||||
|
populateWindowSelection(ui->ignoreIdleWindowsWindows);
|
||||||
|
|
||||||
|
for (auto &window : switcher->ignoreIdleWindows) {
|
||||||
|
QString text = QString::fromStdString(window);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->ignoreIdleWindows);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->idleCheckBox->setChecked(switcher->idleData.idleEnable);
|
||||||
|
ui->idleScenes->setCurrentText(
|
||||||
|
switcher->idleData.usePreviousScene
|
||||||
|
? previous_scene_name
|
||||||
|
: 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);
|
||||||
|
} else {
|
||||||
|
ui->idleScenes->setDisabled(true);
|
||||||
|
ui->idleSpinBox->setDisabled(true);
|
||||||
|
ui->idleTransitions->setDisabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,9 +16,7 @@
|
|||||||
#include <util/platform.h>
|
#include <util/platform.h>
|
||||||
#include "../headers/advanced-scene-switcher.hpp"
|
#include "../headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
using namespace std;
|
static Display *xdisplay = 0;
|
||||||
|
|
||||||
static Display* xdisplay = 0;
|
|
||||||
|
|
||||||
Display *disp()
|
Display *disp()
|
||||||
{
|
{
|
||||||
@@ -40,31 +38,22 @@ void cleanupDisplay()
|
|||||||
static bool ewmhIsSupported()
|
static bool ewmhIsSupported()
|
||||||
{
|
{
|
||||||
Display *display = disp();
|
Display *display = disp();
|
||||||
Atom netSupportingWmCheck = XInternAtom(display,
|
Atom netSupportingWmCheck =
|
||||||
"_NET_SUPPORTING_WM_CHECK", true);
|
XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", true);
|
||||||
Atom actualType;
|
Atom actualType;
|
||||||
int format = 0;
|
int format = 0;
|
||||||
unsigned long num = 0, bytes = 0;
|
unsigned long num = 0, bytes = 0;
|
||||||
unsigned char *data = NULL;
|
unsigned char *data = NULL;
|
||||||
Window ewmh_window = 0;
|
Window ewmh_window = 0;
|
||||||
|
|
||||||
int status = XGetWindowProperty(
|
int status = XGetWindowProperty(display, DefaultRootWindow(display),
|
||||||
display,
|
netSupportingWmCheck, 0L, 1L, false,
|
||||||
DefaultRootWindow(display),
|
XA_WINDOW, &actualType, &format, &num,
|
||||||
netSupportingWmCheck,
|
&bytes, &data);
|
||||||
0L,
|
|
||||||
1L,
|
|
||||||
false,
|
|
||||||
XA_WINDOW,
|
|
||||||
&actualType,
|
|
||||||
&format,
|
|
||||||
&num,
|
|
||||||
&bytes,
|
|
||||||
&data);
|
|
||||||
|
|
||||||
if (status == Success) {
|
if (status == Success) {
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
ewmh_window = ((Window*)data)[0];
|
ewmh_window = ((Window *)data)[0];
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
XFree(data);
|
XFree(data);
|
||||||
@@ -73,21 +62,12 @@ static bool ewmhIsSupported()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ewmh_window) {
|
if (ewmh_window) {
|
||||||
status = XGetWindowProperty(
|
status = XGetWindowProperty(display, ewmh_window,
|
||||||
display,
|
netSupportingWmCheck, 0L, 1L, false,
|
||||||
ewmh_window,
|
XA_WINDOW, &actualType, &format,
|
||||||
netSupportingWmCheck,
|
&num, &bytes, &data);
|
||||||
0L,
|
|
||||||
1L,
|
|
||||||
false,
|
|
||||||
XA_WINDOW,
|
|
||||||
&actualType,
|
|
||||||
&format,
|
|
||||||
&num,
|
|
||||||
&bytes,
|
|
||||||
&data);
|
|
||||||
if (status != Success || num == 0 ||
|
if (status != Success || num == 0 ||
|
||||||
ewmh_window != ((Window*)data)[0]) {
|
ewmh_window != ((Window *)data)[0]) {
|
||||||
ewmh_window = 0;
|
ewmh_window = 0;
|
||||||
}
|
}
|
||||||
if (status == Success && data) {
|
if (status == Success && data) {
|
||||||
@@ -98,6 +78,30 @@ static bool ewmhIsSupported()
|
|||||||
return ewmh_window != 0;
|
return ewmh_window != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QStringList getStates(Window window)
|
||||||
|
{
|
||||||
|
QStringList states;
|
||||||
|
|
||||||
|
if (!ewmhIsSupported())
|
||||||
|
return states;
|
||||||
|
|
||||||
|
Atom wmState = XInternAtom(disp(), "_NET_WM_STATE", true), type;
|
||||||
|
int format;
|
||||||
|
unsigned long num, bytes;
|
||||||
|
unsigned char *data;
|
||||||
|
|
||||||
|
int status = XGetWindowProperty(disp(), window, wmState, 0, ~0L, false,
|
||||||
|
AnyPropertyType, &type, &format, &num,
|
||||||
|
&bytes, &data);
|
||||||
|
|
||||||
|
if (status == Success)
|
||||||
|
for (unsigned long i = 0; i < num; i++)
|
||||||
|
states.append(QString(
|
||||||
|
XGetAtomName(disp(), ((Atom *)data)[i])));
|
||||||
|
|
||||||
|
return states;
|
||||||
|
}
|
||||||
|
|
||||||
static std::vector<Window> getTopLevelWindows()
|
static std::vector<Window> getTopLevelWindows()
|
||||||
{
|
{
|
||||||
std::vector<Window> res;
|
std::vector<Window> res;
|
||||||
@@ -112,24 +116,15 @@ static std::vector<Window> getTopLevelWindows()
|
|||||||
Atom actualType;
|
Atom actualType;
|
||||||
int format;
|
int format;
|
||||||
unsigned long num, bytes;
|
unsigned long num, bytes;
|
||||||
Window* data = 0;
|
Window *data = 0;
|
||||||
|
|
||||||
for (int i = 0; i < ScreenCount(disp()); ++i) {
|
for (int i = 0; i < ScreenCount(disp()); ++i) {
|
||||||
Window rootWin = RootWindow(disp(), i);
|
Window rootWin = RootWindow(disp(), i);
|
||||||
|
|
||||||
int status = XGetWindowProperty(
|
int status = XGetWindowProperty(disp(), rootWin, netClList, 0L,
|
||||||
disp(),
|
~0L, false, AnyPropertyType,
|
||||||
rootWin,
|
&actualType, &format, &num,
|
||||||
netClList,
|
&bytes, (uint8_t **)&data);
|
||||||
0L,
|
|
||||||
~0L,
|
|
||||||
false,
|
|
||||||
AnyPropertyType,
|
|
||||||
&actualType,
|
|
||||||
&format,
|
|
||||||
&num,
|
|
||||||
&bytes,
|
|
||||||
(uint8_t**)&data);
|
|
||||||
|
|
||||||
if (status != Success) {
|
if (status != Success) {
|
||||||
continue;
|
continue;
|
||||||
@@ -148,33 +143,47 @@ static std::string GetWindowTitle(size_t i)
|
|||||||
{
|
{
|
||||||
Window w = getTopLevelWindows().at(i);
|
Window w = getTopLevelWindows().at(i);
|
||||||
std::string windowTitle;
|
std::string windowTitle;
|
||||||
char* name;
|
char *name;
|
||||||
|
|
||||||
XTextProperty text;
|
XTextProperty text;
|
||||||
int status = XGetWMName(disp(), w, &text);
|
int status = XGetTextProperty(
|
||||||
name = reinterpret_cast<char*>(text.value);
|
disp(), w, &text, XInternAtom(disp(), "_NET_WM_NAME", true));
|
||||||
if (status >= Success && name != nullptr)
|
if (status == 0)
|
||||||
{
|
status = XGetTextProperty(disp(), w, &text,
|
||||||
|
XInternAtom(disp(), "WM_NAME", true));
|
||||||
|
name = reinterpret_cast<char *>(text.value);
|
||||||
|
|
||||||
|
if (status != 0 && name != nullptr) {
|
||||||
std::string str(name);
|
std::string str(name);
|
||||||
windowTitle = str;
|
windowTitle = str;
|
||||||
|
XFree(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(name);
|
|
||||||
|
|
||||||
return windowTitle;
|
return windowTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetWindowList(vector<string> &windows)
|
void GetWindowList(std::vector<std::string> &windows)
|
||||||
{
|
{
|
||||||
windows.resize(0);
|
windows.resize(0);
|
||||||
|
|
||||||
for (size_t i = 0; i < getTopLevelWindows().size(); ++i){
|
for (size_t i = 0; i < getTopLevelWindows().size(); ++i) {
|
||||||
if (GetWindowTitle(i) != "")
|
if (GetWindowTitle(i) != "")
|
||||||
windows.emplace_back(GetWindowTitle(i));
|
windows.emplace_back(GetWindowTitle(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCurrentWindowTitle(string &title)
|
// Overloaded
|
||||||
|
void GetWindowList(QStringList &windows)
|
||||||
|
{
|
||||||
|
windows.clear();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < getTopLevelWindows().size(); ++i) {
|
||||||
|
if (GetWindowTitle(i) != "")
|
||||||
|
windows << QString::fromStdString(GetWindowTitle(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetCurrentWindowTitle(std::string &title)
|
||||||
{
|
{
|
||||||
if (!ewmhIsSupported()) {
|
if (!ewmhIsSupported()) {
|
||||||
return;
|
return;
|
||||||
@@ -184,40 +193,39 @@ void GetCurrentWindowTitle(string &title)
|
|||||||
Atom actualType;
|
Atom actualType;
|
||||||
int format;
|
int format;
|
||||||
unsigned long num, bytes;
|
unsigned long num, bytes;
|
||||||
Window* data = 0;
|
Window *data = 0;
|
||||||
char* name;
|
char *name;
|
||||||
|
|
||||||
Window rootWin = RootWindow(disp(), 0);
|
Window rootWin = RootWindow(disp(), 0);
|
||||||
|
|
||||||
XGetWindowProperty(
|
int xstatus = XGetWindowProperty(disp(), rootWin, active, 0L, ~0L,
|
||||||
disp(),
|
false, AnyPropertyType, &actualType,
|
||||||
rootWin,
|
&format, &num, &bytes,
|
||||||
active,
|
(uint8_t **)&data);
|
||||||
0L,
|
|
||||||
~0L,
|
|
||||||
false,
|
|
||||||
AnyPropertyType,
|
|
||||||
&actualType,
|
|
||||||
&format,
|
|
||||||
&num,
|
|
||||||
&bytes,
|
|
||||||
(uint8_t**)&data);
|
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
XTextProperty text;
|
XTextProperty text;
|
||||||
int status = XGetWMName(disp(), data[0], &text);
|
if (xstatus == Success) {
|
||||||
name = reinterpret_cast<char*>(text.value);
|
status = XGetTextProperty(disp(), data[0], &text,
|
||||||
|
XInternAtom(disp(), "_NET_WM_NAME",
|
||||||
|
true));
|
||||||
|
if (status == 0)
|
||||||
|
status = XGetTextProperty(disp(), data[0], &text,
|
||||||
|
XInternAtom(disp(), "WM_NAME",
|
||||||
|
true));
|
||||||
|
}
|
||||||
|
name = reinterpret_cast<char *>(text.value);
|
||||||
|
|
||||||
if (status >= Success && name != nullptr) {
|
if (status != 0 && name != nullptr) {
|
||||||
std::string str(name);
|
std::string str(name);
|
||||||
title = str;
|
title = str;
|
||||||
|
XFree(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<int, int> getCursorPos()
|
std::pair<int, int> getCursorPos()
|
||||||
{
|
{
|
||||||
pair<int, int> pos(0, 0);
|
std::pair<int, int> pos(0, 0);
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Window root;
|
Window root;
|
||||||
Window ret_root;
|
Window ret_root;
|
||||||
@@ -231,95 +239,108 @@ pair<int, int> getCursorPos()
|
|||||||
dpy = XOpenDisplay(NULL);
|
dpy = XOpenDisplay(NULL);
|
||||||
root = XDefaultRootWindow(dpy);
|
root = XDefaultRootWindow(dpy);
|
||||||
|
|
||||||
if(XQueryPointer(dpy, root, &ret_root, &ret_child, &root_x, &root_y,
|
if (XQueryPointer(dpy, root, &ret_root, &ret_child, &root_x, &root_y,
|
||||||
&win_x, &win_y, &mask))
|
&win_x, &win_y, &mask)) {
|
||||||
{
|
pos = std::pair<int, int>(root_x, root_y);
|
||||||
pos = pair<int, int> (root_x,root_y);
|
|
||||||
}
|
}
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFullscreen()
|
bool isFullscreen(std::string &title)
|
||||||
{
|
{
|
||||||
if (!ewmhIsSupported()) {
|
if (!ewmhIsSupported())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Find switch in top level windows
|
||||||
|
std::vector<Window> windows = getTopLevelWindows();
|
||||||
|
for (auto &window : windows) {
|
||||||
|
XTextProperty text;
|
||||||
|
int status = XGetTextProperty(
|
||||||
|
disp(), window, &text,
|
||||||
|
XInternAtom(disp(), "_NET_WM_NAME", true));
|
||||||
|
if (status == 0)
|
||||||
|
status = XGetTextProperty(disp(), window, &text,
|
||||||
|
XInternAtom(disp(), "WM_NAME",
|
||||||
|
true));
|
||||||
|
char *name = reinterpret_cast<char *>(text.value);
|
||||||
|
|
||||||
|
if (status == 0 || name == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// True if switch equals window
|
||||||
|
bool equals = (title == name);
|
||||||
|
// True if switch matches window
|
||||||
|
bool matches = QString::fromStdString(name).contains(
|
||||||
|
QRegularExpression(QString::fromStdString(title)));
|
||||||
|
|
||||||
|
// If found, check if switch is fullscreen
|
||||||
|
if (equals || matches) {
|
||||||
|
QStringList states = getStates(window);
|
||||||
|
|
||||||
|
if (!states.isEmpty()) {
|
||||||
|
// True if window is fullscreen
|
||||||
|
bool fullscreen = states.contains(
|
||||||
|
"_NET_WM_STATE_FULLSCREEN");
|
||||||
|
// True if window is maximized vertically
|
||||||
|
bool vertical = states.contains(
|
||||||
|
"_NET_WM_STATE_MAXIMIZED_VERT");
|
||||||
|
// True if window is maximized horizontally
|
||||||
|
bool horizontal = states.contains(
|
||||||
|
"_NET_WM_STATE_MAXIMIZED_HORZ");
|
||||||
|
|
||||||
|
return (fullscreen || (vertical && horizontal));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom active = XInternAtom(disp(), "_NET_ACTIVE_WINDOW", true);
|
return false;
|
||||||
Atom actualType;
|
|
||||||
int format;
|
|
||||||
unsigned long num, bytes;
|
|
||||||
Window* data = 0;
|
|
||||||
|
|
||||||
Window rootWin = RootWindow(disp(), 0);
|
|
||||||
XGetWindowProperty(
|
|
||||||
disp(),
|
|
||||||
rootWin,
|
|
||||||
active,
|
|
||||||
0L,
|
|
||||||
~0L,
|
|
||||||
false,
|
|
||||||
AnyPropertyType,
|
|
||||||
&actualType,
|
|
||||||
&format,
|
|
||||||
&num,
|
|
||||||
&bytes,
|
|
||||||
(uint8_t**)&data);
|
|
||||||
|
|
||||||
|
|
||||||
XWindowAttributes window_attributes_return;
|
|
||||||
XWindowAttributes screen_attributes_return;
|
|
||||||
|
|
||||||
XGetWindowAttributes(disp(), rootWin, &screen_attributes_return);
|
|
||||||
XGetWindowAttributes(disp(), data[0], &window_attributes_return);
|
|
||||||
|
|
||||||
//menu bar is always 24 pixels in height
|
|
||||||
return (window_attributes_return.width >= screen_attributes_return.width &&
|
|
||||||
window_attributes_return.height + 24 >= screen_attributes_return.height) ? true : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//exe switch is not quite what is expected but it works for now
|
//exe switch is not quite what is expected but it works for now
|
||||||
void GetProcessList(QStringList &processes)
|
void GetProcessList(QStringList &processes)
|
||||||
{
|
{
|
||||||
processes.clear();
|
processes.clear();
|
||||||
for (size_t i = 0; i < getTopLevelWindows().size(); ++i){
|
for (size_t i = 0; i < getTopLevelWindows().size(); ++i) {
|
||||||
string s = GetWindowTitle(i);
|
std::string s = GetWindowTitle(i);
|
||||||
if (s != "")
|
if (s != "")
|
||||||
processes << QString::fromStdString(s);
|
processes << QString::fromStdString(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInFocus(const QString &exeToCheck)
|
bool isInFocus(const QString &executable)
|
||||||
{
|
{
|
||||||
string curWindow;
|
std::string current;
|
||||||
GetCurrentWindowTitle(curWindow);
|
GetCurrentWindowTitle(current);
|
||||||
|
|
||||||
return (QString::compare(
|
// True if executable switch equals current window
|
||||||
QString::fromStdString(curWindow),
|
bool equals = (executable.toStdString() == current);
|
||||||
exeToCheck,
|
// True if executable switch matches current window
|
||||||
Qt::CaseInsensitive) == 0) ? true : false;
|
bool matches = QString::fromStdString(current).contains(
|
||||||
|
QRegularExpression(executable));
|
||||||
|
|
||||||
|
return (equals || matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int secondsSinceLastInput()
|
int secondsSinceLastInput()
|
||||||
{
|
{
|
||||||
time_t idle_time;
|
time_t idle_time;
|
||||||
static XScreenSaverInfo *mit_info;
|
static XScreenSaverInfo *mit_info;
|
||||||
Display *display;
|
Display *display;
|
||||||
int screen;
|
int screen;
|
||||||
|
|
||||||
mit_info = XScreenSaverAllocInfo();
|
mit_info = XScreenSaverAllocInfo();
|
||||||
|
|
||||||
if((display=XOpenDisplay(NULL)) == NULL)
|
if ((display = XOpenDisplay(NULL)) == NULL) {
|
||||||
{
|
return (-1);
|
||||||
return(-1);
|
|
||||||
}
|
}
|
||||||
screen = DefaultScreen(display);
|
screen = DefaultScreen(display);
|
||||||
XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info);
|
XScreenSaverQueryInfo(display, RootWindow(display, screen), mit_info);
|
||||||
idle_time = (mit_info->idle) / 1000;
|
idle_time = (mit_info->idle) / 1000;
|
||||||
XFree(mit_info);
|
XFree(mit_info);
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
|
|
||||||
return idle_time;
|
return idle_time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,37 @@
|
|||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
void SceneSwitcher::on_mediaSwitches_currentRowChanged(int idx)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QListWidgetItem *item = ui->mediaSwitches->item(idx);
|
||||||
|
|
||||||
|
QString mediaSceneStr = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
for (auto &s : switcher->mediaSwitches) {
|
||||||
|
if (mediaSceneStr.compare(s.mediaSwitchStr.c_str()) == 0) {
|
||||||
|
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
||||||
|
QString sourceName =
|
||||||
|
GetWeakSourceName(s.source).c_str();
|
||||||
|
QString transitionName =
|
||||||
|
GetWeakSourceName(s.transition).c_str();
|
||||||
|
ui->mediaScenes->setCurrentText(sceneName);
|
||||||
|
ui->mediaSources->setCurrentText(sourceName);
|
||||||
|
ui->mediaTransitions->setCurrentText(transitionName);
|
||||||
|
ui->mediaStates->setCurrentIndex(s.state);
|
||||||
|
ui->mediaTimeRestrictions->setCurrentIndex(
|
||||||
|
s.restriction);
|
||||||
|
ui->mediaTime->setValue(s.time);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_mediaAdd_clicked()
|
void SceneSwitcher::on_mediaAdd_clicked()
|
||||||
{
|
{
|
||||||
QString sourceName = ui->mediaSources->currentText();
|
QString sourceName = ui->mediaSources->currentText();
|
||||||
@@ -29,10 +60,11 @@ void SceneSwitcher::on_mediaAdd_clicked()
|
|||||||
new QListWidgetItem(switchText, ui->mediaSwitches);
|
new QListWidgetItem(switchText, ui->mediaSwitches);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->mediaSwitches.emplace_back(
|
switcher->mediaSwitches.emplace_back(
|
||||||
scene, source, transition, state, restriction, time,
|
scene, source, transition, state, restriction, time,
|
||||||
(sceneName == QString(PREVIOUS_SCENE_NAME)));
|
(sceneName == QString(previous_scene_name)),
|
||||||
|
switchText.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_mediaRemove_clicked()
|
void SceneSwitcher::on_mediaRemove_clicked()
|
||||||
@@ -41,17 +73,66 @@ void SceneSwitcher::on_mediaRemove_clicked()
|
|||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int idx = ui->mediaSwitches->currentRow();
|
std::string mediaStr =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
auto &switches = switcher->mediaSwitches;
|
||||||
|
|
||||||
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
|
auto &s = *it;
|
||||||
|
|
||||||
|
if (s.mediaSwitchStr == mediaStr) {
|
||||||
|
switches.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_mediaUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->mediaSwitches->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->mediaSwitches->insertItem(
|
||||||
|
index - 1, ui->mediaSwitches->takeItem(index));
|
||||||
|
ui->mediaSwitches->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->mediaSwitches.begin() + index,
|
||||||
|
switcher->mediaSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_mediaDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->mediaSwitches->currentRow();
|
||||||
|
if (index != -1 && index != ui->mediaSwitches->count() - 1) {
|
||||||
|
ui->mediaSwitches->insertItem(
|
||||||
|
index + 1, ui->mediaSwitches->takeItem(index));
|
||||||
|
ui->mediaSwitches->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->mediaSwitches.begin() + index,
|
||||||
|
switcher->mediaSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_mediaTimeRestrictions_currentIndexChanged(int idx)
|
||||||
|
{
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
if ((time_restriction)ui->mediaTimeRestrictions->currentIndex() ==
|
||||||
lock_guard<mutex> lock(switcher->m);
|
TIME_RESTRICTION_NONE) {
|
||||||
|
ui->mediaTime->setDisabled(true);
|
||||||
auto &switches = switcher->mediaSwitches;
|
} else {
|
||||||
switches.erase(switches.begin() + idx);
|
ui->mediaTime->setDisabled(false);
|
||||||
}
|
}
|
||||||
qDeleteAll(ui->mediaSwitches->selectedItems());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
|
void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
|
||||||
@@ -84,7 +165,137 @@ void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,
|
|||||||
? previousScene
|
? previousScene
|
||||||
: mediaSwitch.scene;
|
: mediaSwitch.scene;
|
||||||
transition = mediaSwitch.transition;
|
transition = mediaSwitch.transition;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher meida match");
|
||||||
}
|
}
|
||||||
mediaSwitch.matched = matched;
|
mediaSwitch.matched = matched;
|
||||||
|
obs_source_release(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveMediaSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *mediaArray = obs_data_array_create();
|
||||||
|
for (MediaSwitch &s : switcher->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);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "mediaSwitches", mediaArray);
|
||||||
|
obs_data_array_release(mediaArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadMediaSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *mediaArray = obs_data_get_array(obj, "mediaSwitches");
|
||||||
|
switcher->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");
|
||||||
|
|
||||||
|
std::string mediaStr = MakeMediaSwitchName(source, scene,
|
||||||
|
transition, state,
|
||||||
|
restriction, time)
|
||||||
|
.toUtf8()
|
||||||
|
.constData();
|
||||||
|
|
||||||
|
switcher->mediaSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene), GetWeakSourceByName(source),
|
||||||
|
GetWeakTransitionByName(transition), state, restriction,
|
||||||
|
time, (strcmp(scene, previous_scene_name) == 0),
|
||||||
|
mediaStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(mediaArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupMediaTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->mediaScenes, true);
|
||||||
|
populateTransitionSelection(ui->mediaTransitions);
|
||||||
|
|
||||||
|
auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */
|
||||||
|
{
|
||||||
|
QComboBox *combo = reinterpret_cast<QComboBox *>(data);
|
||||||
|
if (strcmp(obs_source_get_id(source), "ffmpeg_source") == 0) {
|
||||||
|
const char *name = obs_source_get_name(source);
|
||||||
|
combo->addItem(name);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
obs_enum_sources(sourceEnum, ui->mediaSources);
|
||||||
|
|
||||||
|
ui->mediaStates->addItem("None");
|
||||||
|
ui->mediaStates->addItem("Playing");
|
||||||
|
ui->mediaStates->addItem("Opening");
|
||||||
|
ui->mediaStates->addItem("Buffering");
|
||||||
|
ui->mediaStates->addItem("Paused");
|
||||||
|
ui->mediaStates->addItem("Stopped");
|
||||||
|
ui->mediaStates->addItem("Ended");
|
||||||
|
ui->mediaStates->addItem("Error");
|
||||||
|
|
||||||
|
ui->mediaTimeRestrictions->addItem("None");
|
||||||
|
ui->mediaTimeRestrictions->addItem("Time shorter");
|
||||||
|
ui->mediaTimeRestrictions->addItem("Time longer");
|
||||||
|
ui->mediaTimeRestrictions->addItem("Time remaining shorter");
|
||||||
|
ui->mediaTimeRestrictions->addItem("Time remaining longer");
|
||||||
|
|
||||||
|
for (auto &s : switcher->mediaSwitches) {
|
||||||
|
std::string sourceName = GetWeakSourceName(s.source);
|
||||||
|
std::string sceneName = (s.usePreviousScene)
|
||||||
|
? previous_scene_name
|
||||||
|
: GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString listText = MakeMediaSwitchName(
|
||||||
|
sourceName.c_str(), sceneName.c_str(),
|
||||||
|
transitionName.c_str(), s.state, s.restriction, s.time);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(listText, ui->mediaSwitches);
|
||||||
|
item->setData(Qt::UserRole, listText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,141 +6,232 @@
|
|||||||
#include <util/platform.h>
|
#include <util/platform.h>
|
||||||
#include "../headers/advanced-scene-switcher.hpp"
|
#include "../headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
void GetWindowList(std::vector<std::string> &windows)
|
||||||
void GetWindowList(vector<string> &windows)
|
|
||||||
{
|
{
|
||||||
windows.resize(0);
|
windows.resize(0);
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
NSMutableArray *apps =
|
||||||
NSArray *array = [ws runningApplications];
|
(__bridge NSMutableArray *)CGWindowListCopyWindowInfo(
|
||||||
for (NSRunningApplication *app in array) {
|
kCGWindowListOptionAll, kCGNullWindowID);
|
||||||
NSString *name = app.localizedName;
|
for (NSDictionary *app in apps) {
|
||||||
if (!name)
|
// Construct string from NSString accounting for nil
|
||||||
continue;
|
std::string name([[app objectForKey:@"kCGWindowName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
std::string owner([[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
|
||||||
const char *str = name.UTF8String;
|
// Check if name exists
|
||||||
if (str && *str)
|
if (!name.empty() &&
|
||||||
windows.emplace_back(str);
|
find(windows.begin(), windows.end(), name) ==
|
||||||
}
|
windows.end())
|
||||||
}
|
windows.emplace_back(name);
|
||||||
|
// Check if owner exists
|
||||||
|
else if (!owner.empty() &&
|
||||||
|
find(windows.begin(), windows.end(), owner) ==
|
||||||
|
windows.end())
|
||||||
|
windows.emplace_back(owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCurrentWindowTitle(string &title)
|
// Overloaded
|
||||||
|
void GetWindowList(QStringList &windows)
|
||||||
{
|
{
|
||||||
title.resize(0);
|
windows.clear();
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
NSMutableArray *apps =
|
||||||
NSRunningApplication *app = [ws frontmostApplication];
|
(__bridge NSMutableArray *)CGWindowListCopyWindowInfo(
|
||||||
if (app) {
|
kCGWindowListOptionAll, kCGNullWindowID);
|
||||||
NSString *name = app.localizedName;
|
for (NSDictionary *app in apps) {
|
||||||
if (!name)
|
// Construct string from NSString accounting for nil
|
||||||
return;
|
std::string name([[app objectForKey:@"kCGWindowName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
std::string owner([[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
|
||||||
const char *str = name.UTF8String;
|
// Check if name exists
|
||||||
if (str && *str)
|
if (!name.empty() &&
|
||||||
title = str;
|
!windows.contains(QString::fromStdString(name)))
|
||||||
}
|
windows << QString::fromStdString(name);
|
||||||
}
|
// Check if owner exists
|
||||||
|
else if (!owner.empty() &&
|
||||||
|
!windows.contains(
|
||||||
|
QString::fromStdString(name)))
|
||||||
|
windows << QString::fromStdString(owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<int, int> getCursorPos() {
|
void GetCurrentWindowTitle(std::string &title)
|
||||||
pair<int, int> pos(0, 0);
|
{
|
||||||
CGEventRef event = CGEventCreate(NULL);
|
title.resize(0);
|
||||||
CGPoint cursorPos = CGEventGetLocation(event);
|
|
||||||
CFRelease(event);
|
|
||||||
pos.first = cursorPos.x;
|
|
||||||
pos.second = cursorPos.y;
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isFullscreen() {
|
@autoreleasepool {
|
||||||
@autoreleasepool {
|
NSMutableArray *apps =
|
||||||
AXValueRef temp;
|
(__bridge NSMutableArray *)CGWindowListCopyWindowInfo(
|
||||||
CGSize windowSize;
|
kCGWindowListOptionOnScreenOnly,
|
||||||
CGPoint windowPosition;
|
kCGNullWindowID);
|
||||||
AXUIElementRef frontMostApp;
|
for (NSDictionary *app in apps) {
|
||||||
AXUIElementRef frontMostWindow;
|
int layer =
|
||||||
|
[[app objectForKey:@"kCGWindowLayer"] intValue];
|
||||||
|
// True if window is frontmost
|
||||||
|
if (layer == 0) {
|
||||||
|
// Construct string from NSString accounting for nil
|
||||||
|
std::string name(
|
||||||
|
[[app objectForKey:@"kCGWindowName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
std::string owner(
|
||||||
|
[[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
|
||||||
pid_t pid;
|
if (!name.empty())
|
||||||
ProcessSerialNumber psn;
|
title = name;
|
||||||
@try {
|
else if (!owner.empty())
|
||||||
GetFrontProcess(&psn);
|
title = owner;
|
||||||
GetProcessPID(&psn, &pid);
|
|
||||||
frontMostApp = AXUIElementCreateApplication(pid);
|
|
||||||
|
|
||||||
AXUIElementCopyAttributeValue(
|
break;
|
||||||
frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the window size and position
|
std::pair<int, int> getCursorPos()
|
||||||
AXUIElementCopyAttributeValue(
|
{
|
||||||
frontMostWindow, kAXSizeAttribute, (CFTypeRef *)&temp);
|
std::pair<int, int> pos(0, 0);
|
||||||
AXValueGetValue(temp, kAXValueTypeCGSize, &windowSize);
|
CGEventRef event = CGEventCreate(NULL);
|
||||||
CFRelease(temp);
|
CGPoint cursorPos = CGEventGetLocation(event);
|
||||||
|
CFRelease(event);
|
||||||
|
pos.first = cursorPos.x;
|
||||||
|
pos.second = cursorPos.y;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
AXUIElementCopyAttributeValue(
|
bool isFullscreen(std::string &title)
|
||||||
frontMostWindow, kAXPositionAttribute, (CFTypeRef *)&temp);
|
{
|
||||||
AXValueGetValue(temp, kAXValueTypeCGPoint, &windowPosition);
|
// Check for match
|
||||||
CFRelease(temp);
|
@autoreleasepool {
|
||||||
|
NSArray *screens = [NSScreen screens];
|
||||||
|
NSMutableArray *apps =
|
||||||
|
(__bridge NSMutableArray *)CGWindowListCopyWindowInfo(
|
||||||
|
kCGWindowListOptionAll, kCGNullWindowID);
|
||||||
|
for (NSDictionary *app in apps) {
|
||||||
|
// Construct string from NSString accounting for nil
|
||||||
|
std::string name([[app objectForKey:@"kCGWindowName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
std::string owner([[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
UTF8String],
|
||||||
|
[[app objectForKey:@"kCGWindowOwnerName"]
|
||||||
|
lengthOfBytesUsingEncoding:
|
||||||
|
NSUTF8StringEncoding]);
|
||||||
|
|
||||||
CGRect screenBound = CGDisplayBounds(CGMainDisplayID());
|
// True if switch equals app
|
||||||
CGSize screenSize = screenBound.size;
|
bool equals = (title == name || title == owner);
|
||||||
|
// True if switch matches app
|
||||||
|
bool matches = (QString::fromStdString(name).contains(
|
||||||
|
QRegularExpression(
|
||||||
|
QString::fromStdString(
|
||||||
|
title))) ||
|
||||||
|
QString::fromStdString(owner).contains(
|
||||||
|
QRegularExpression(
|
||||||
|
QString::fromStdString(
|
||||||
|
title))));
|
||||||
|
|
||||||
if((windowSize.width == screenSize.width) && (windowSize.height == screenSize.height) &&
|
// If found, check if fullscreen
|
||||||
(windowPosition.x == 0) && (windowPosition.y == 0))
|
if (equals || matches) {
|
||||||
return true;
|
// Get window bounds
|
||||||
}
|
NSRect bounds;
|
||||||
@catch (...) {
|
CGRectMakeWithDictionaryRepresentation(
|
||||||
// deal with the exception
|
(CFDictionaryRef)[app
|
||||||
}
|
objectForKey:@"kCGWindowBounds"],
|
||||||
@catch (NSException *exception) {
|
&bounds);
|
||||||
// deal with the exception
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// Compare to screen bounds
|
||||||
return false;
|
for (NSScreen *screen in screens) {
|
||||||
|
NSRect frame = [screen visibleFrame];
|
||||||
|
|
||||||
|
// True if flipped window origin equals screen origin
|
||||||
|
bool origin =
|
||||||
|
(bounds.origin.x ==
|
||||||
|
frame.origin.x &&
|
||||||
|
([screens[0] visibleFrame]
|
||||||
|
.size.height -
|
||||||
|
frame.size.height -
|
||||||
|
bounds.origin.y ==
|
||||||
|
frame.origin.y));
|
||||||
|
// True if window size equals screen size
|
||||||
|
bool size = NSEqualSizes(bounds.size,
|
||||||
|
frame.size);
|
||||||
|
|
||||||
|
if (origin && size)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int secondsSinceLastInput()
|
int secondsSinceLastInput()
|
||||||
{
|
{
|
||||||
double time = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType) + 0.5;
|
double time = CGEventSourceSecondsSinceLastEventType(
|
||||||
return (int) time;
|
kCGEventSourceStateCombinedSessionState,
|
||||||
|
kCGAnyInputEventType) +
|
||||||
|
0.5;
|
||||||
|
return (int)time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetProcessList(QStringList& list)
|
void GetProcessList(QStringList &list)
|
||||||
{
|
{
|
||||||
list.clear();
|
list.clear();
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||||
NSArray *array = [ws runningApplications];
|
NSArray *array = [ws runningApplications];
|
||||||
for (NSRunningApplication *app in array) {
|
for (NSRunningApplication *app in array) {
|
||||||
NSString *name = app.localizedName;
|
NSString *name = app.localizedName;
|
||||||
if (!name)
|
if (!name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char *str = name.UTF8String;
|
const char *str = name.UTF8String;
|
||||||
if (str && *str)
|
if (str && *str)
|
||||||
list << (str);
|
list << (str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInFocus(QString const& appQName)
|
bool isInFocus(const QString &executable)
|
||||||
{
|
{
|
||||||
QByteArray ba = appQName.toLocal8Bit();
|
std::string current;
|
||||||
const char * appName = ba.data();
|
GetCurrentWindowTitle(current);
|
||||||
@autoreleasepool {
|
|
||||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
// True if executable switch equals current window
|
||||||
NSRunningApplication *app = [ws frontmostApplication];
|
bool equals = (executable.toStdString() == current);
|
||||||
if (app) {
|
// True if executable switch matches current window
|
||||||
NSString *name = app.localizedName;
|
bool matches = QString::fromStdString(current).contains(
|
||||||
if (!name)
|
QRegularExpression(executable));
|
||||||
return false;
|
|
||||||
|
return (equals || matches);
|
||||||
const char *str = name.UTF8String;
|
|
||||||
return (str && *str && strcmp(appName,str) == 0 )? true : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ void SceneSwitcher::on_pauseScenesAdd_clicked()
|
|||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
QVariant v = QVariant::fromValue(sceneName);
|
QVariant v = QVariant::fromValue(sceneName);
|
||||||
|
|
||||||
QList<QListWidgetItem*> items = ui->pauseScenes->findItems(sceneName, Qt::MatchExactly);
|
QList<QListWidgetItem *> items =
|
||||||
|
ui->pauseScenes->findItems(sceneName, Qt::MatchExactly);
|
||||||
|
|
||||||
if (items.size() == 0)
|
if (items.size() == 0) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(sceneName, ui->pauseScenes);
|
new QListWidgetItem(sceneName, ui->pauseScenes);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->pauseScenesSwitches.emplace_back(source);
|
switcher->pauseScenesSwitches.emplace_back(source);
|
||||||
ui->pauseScenes->sortItems();
|
ui->pauseScenes->sortItems();
|
||||||
}
|
}
|
||||||
@@ -25,22 +26,20 @@ void SceneSwitcher::on_pauseScenesAdd_clicked()
|
|||||||
|
|
||||||
void SceneSwitcher::on_pauseScenesRemove_clicked()
|
void SceneSwitcher::on_pauseScenesRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->pauseScenes->currentItem();
|
QListWidgetItem *item = ui->pauseScenes->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString pauseScene = item->data(Qt::UserRole).toString();
|
QString pauseScene = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->pauseScenesSwitches;
|
auto &switches = switcher->pauseScenesSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s == GetWeakSourceByQString(pauseScene))
|
if (s == GetWeakSourceByQString(pauseScene)) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -59,37 +58,37 @@ void SceneSwitcher::on_pauseWindowsAdd_clicked()
|
|||||||
|
|
||||||
QVariant v = QVariant::fromValue(windowName);
|
QVariant v = QVariant::fromValue(windowName);
|
||||||
|
|
||||||
QList<QListWidgetItem*> items = ui->pauseWindows->findItems(windowName, Qt::MatchExactly);
|
QList<QListWidgetItem *> items =
|
||||||
|
ui->pauseWindows->findItems(windowName, Qt::MatchExactly);
|
||||||
|
|
||||||
if (items.size() == 0)
|
if (items.size() == 0) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(windowName, ui->pauseWindows);
|
new QListWidgetItem(windowName, ui->pauseWindows);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->pauseWindowsSwitches.emplace_back(windowName.toUtf8().constData());
|
switcher->pauseWindowsSwitches.emplace_back(
|
||||||
|
windowName.toUtf8().constData());
|
||||||
ui->pauseWindows->sortItems();
|
ui->pauseWindows->sortItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_pauseWindowsRemove_clicked()
|
void SceneSwitcher::on_pauseWindowsRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->pauseWindows->currentItem();
|
QListWidgetItem *item = ui->pauseWindows->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString windowName = item->data(Qt::UserRole).toString();
|
QString windowName = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->pauseWindowsSwitches;
|
auto &switches = switcher->pauseWindowsSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s == windowName.toUtf8().constData())
|
if (s == windowName.toUtf8().constData()) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -106,16 +105,14 @@ void SceneSwitcher::on_pauseScenes_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->pauseScenes->item(idx);
|
QListWidgetItem *item = ui->pauseScenes->item(idx);
|
||||||
|
|
||||||
QString scene = item->data(Qt::UserRole).toString();
|
QString scene = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->pauseScenesSwitches)
|
for (auto &s : switcher->pauseScenesSwitches) {
|
||||||
{
|
std::string name = GetWeakSourceName(s);
|
||||||
string name = GetWeakSourceName(s);
|
if (scene.compare(name.c_str()) == 0) {
|
||||||
if (scene.compare(name.c_str()) == 0)
|
|
||||||
{
|
|
||||||
ui->pauseScenesScenes->setCurrentText(name.c_str());
|
ui->pauseScenesScenes->setCurrentText(name.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -129,33 +126,29 @@ void SceneSwitcher::on_pauseWindows_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->pauseWindows->item(idx);
|
QListWidgetItem *item = ui->pauseWindows->item(idx);
|
||||||
|
|
||||||
QString window = item->data(Qt::UserRole).toString();
|
QString window = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->pauseWindowsSwitches)
|
for (auto &s : switcher->pauseWindowsSwitches) {
|
||||||
{
|
if (window.compare(s.c_str()) == 0) {
|
||||||
if (window.compare(s.c_str()) == 0)
|
|
||||||
{
|
|
||||||
ui->pauseWindowsWindows->setCurrentText(s.c_str());
|
ui->pauseWindowsWindows->setCurrentText(s.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::PauseScenesFindByData(const QString& scene)
|
int SceneSwitcher::PauseScenesFindByData(const QString &scene)
|
||||||
{
|
{
|
||||||
int count = ui->pauseScenes->count();
|
int count = ui->pauseScenes->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->pauseScenes->item(i);
|
||||||
QListWidgetItem* item = ui->pauseScenes->item(i);
|
|
||||||
QString itemRegion = item->data(Qt::UserRole).toString();
|
QString itemRegion = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemRegion == scene)
|
if (itemRegion == scene) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -164,18 +157,16 @@ int SceneSwitcher::PauseScenesFindByData(const QString& scene)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::PauseWindowsFindByData(const QString& window)
|
int SceneSwitcher::PauseWindowsFindByData(const QString &window)
|
||||||
{
|
{
|
||||||
int count = ui->pauseWindows->count();
|
int count = ui->pauseWindows->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->pauseWindows->item(i);
|
||||||
QListWidgetItem* item = ui->pauseWindows->item(i);
|
|
||||||
QString itemRegion = item->data(Qt::UserRole).toString();
|
QString itemRegion = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemRegion == window)
|
if (itemRegion == window) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -187,13 +178,11 @@ int SceneSwitcher::PauseWindowsFindByData(const QString& window)
|
|||||||
bool SwitcherData::checkPause()
|
bool SwitcherData::checkPause()
|
||||||
{
|
{
|
||||||
bool pause = false;
|
bool pause = false;
|
||||||
obs_source_t* currentSource = obs_frontend_get_current_scene();
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(currentSource);
|
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
|
||||||
|
|
||||||
for (OBSWeakSource& s : pauseScenesSwitches)
|
for (OBSWeakSource &s : pauseScenesSwitches) {
|
||||||
{
|
if (s == ws) {
|
||||||
if (s == ws)
|
|
||||||
{
|
|
||||||
pause = true;
|
pause = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -201,42 +190,133 @@ bool SwitcherData::checkPause()
|
|||||||
obs_source_release(currentSource);
|
obs_source_release(currentSource);
|
||||||
obs_weak_source_release(ws);
|
obs_weak_source_release(ws);
|
||||||
|
|
||||||
string title;
|
std::string title;
|
||||||
if (!pause)
|
if (!pause) {
|
||||||
{
|
|
||||||
//lock.unlock();
|
//lock.unlock();
|
||||||
GetCurrentWindowTitle(title);
|
GetCurrentWindowTitle(title);
|
||||||
//lock.lock();
|
//lock.lock();
|
||||||
for (string& window : pauseWindowsSwitches)
|
for (std::string &window : pauseWindowsSwitches) {
|
||||||
{
|
if (window == title) {
|
||||||
if (window == title)
|
|
||||||
{
|
|
||||||
pause = true;
|
pause = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pause)
|
if (!pause) {
|
||||||
{
|
|
||||||
//lock.unlock();
|
//lock.unlock();
|
||||||
GetCurrentWindowTitle(title);
|
GetCurrentWindowTitle(title);
|
||||||
//lock.lock();
|
//lock.lock();
|
||||||
for (string& window : pauseWindowsSwitches)
|
for (std::string &window : pauseWindowsSwitches) {
|
||||||
{
|
try {
|
||||||
try
|
bool matches = std::regex_match(
|
||||||
{
|
title, std::regex(window));
|
||||||
bool matches = regex_match(title, regex(window));
|
if (matches) {
|
||||||
if (matches)
|
|
||||||
{
|
|
||||||
pause = true;
|
pause = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} catch (const std::regex_error &) {
|
||||||
catch (const regex_error&)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (verbose && pause)
|
||||||
|
blog(LOG_INFO, "Advanced Scene Switcher pause match");
|
||||||
|
|
||||||
return pause;
|
return pause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::savePauseSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *pauseScenesArray = obs_data_array_create();
|
||||||
|
for (OBSWeakSource &scene : switcher->pauseScenesSwitches) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
|
||||||
|
obs_source_t *source = obs_weak_source_get_source(scene);
|
||||||
|
if (source) {
|
||||||
|
const char *n = obs_source_get_name(source);
|
||||||
|
obs_data_set_string(array_obj, "pauseScene", n);
|
||||||
|
obs_data_array_push_back(pauseScenesArray, array_obj);
|
||||||
|
obs_source_release(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "pauseScenes", pauseScenesArray);
|
||||||
|
obs_data_array_release(pauseScenesArray);
|
||||||
|
|
||||||
|
obs_data_array_t *pauseWindowsArray = obs_data_array_create();
|
||||||
|
for (std::string &window : switcher->pauseWindowsSwitches) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
obs_data_set_string(array_obj, "pauseWindow", window.c_str());
|
||||||
|
obs_data_array_push_back(pauseWindowsArray, array_obj);
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "pauseWindows", pauseWindowsArray);
|
||||||
|
obs_data_array_release(pauseWindowsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadPauseSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->pauseScenesSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *pauseScenesArray =
|
||||||
|
obs_data_get_array(obj, "pauseScenes");
|
||||||
|
size_t count = obs_data_array_count(pauseScenesArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(pauseScenesArray, i);
|
||||||
|
|
||||||
|
const char *scene =
|
||||||
|
obs_data_get_string(array_obj, "pauseScene");
|
||||||
|
|
||||||
|
switcher->pauseScenesSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene));
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(pauseScenesArray);
|
||||||
|
|
||||||
|
switcher->pauseWindowsSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *pauseWindowsArray =
|
||||||
|
obs_data_get_array(obj, "pauseWindows");
|
||||||
|
count = obs_data_array_count(pauseWindowsArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(pauseWindowsArray, i);
|
||||||
|
|
||||||
|
const char *window =
|
||||||
|
obs_data_get_string(array_obj, "pauseWindow");
|
||||||
|
|
||||||
|
switcher->pauseWindowsSwitches.emplace_back(window);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(pauseWindowsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupPauseTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->pauseScenesScenes, false);
|
||||||
|
populateWindowSelection(ui->pauseWindowsWindows);
|
||||||
|
|
||||||
|
for (auto &scene : switcher->pauseScenesSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(scene);
|
||||||
|
QString text = QString::fromStdString(sceneName);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->pauseScenes);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &window : switcher->pauseWindowsSwitches) {
|
||||||
|
QString text = QString::fromStdString(window);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->pauseWindows);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,44 +1,68 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
void SceneSwitcher::on_threadPriority_currentTextChanged(const QString &text)
|
||||||
|
{
|
||||||
|
if (loading ||
|
||||||
|
ui->threadPriority->count() != switcher->threadPriorities.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
for (auto p : switcher->threadPriorities) {
|
||||||
|
if (p.name == text.toUtf8().constData()) {
|
||||||
|
switcher->threadPriority = p.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_priorityUp_clicked()
|
void SceneSwitcher::on_priorityUp_clicked()
|
||||||
{
|
{
|
||||||
int currentIndex = ui->priorityList->currentRow();
|
int currentIndex = ui->priorityList->currentRow();
|
||||||
if (currentIndex != -1 && currentIndex != 0)
|
if (currentIndex != -1 && currentIndex != 0) {
|
||||||
{
|
ui->priorityList->insertItem(
|
||||||
ui->priorityList->insertItem(currentIndex - 1 ,ui->priorityList->takeItem(currentIndex));
|
currentIndex - 1,
|
||||||
ui->priorityList->setCurrentRow(currentIndex -1);
|
ui->priorityList->takeItem(currentIndex));
|
||||||
lock_guard<mutex> lock(switcher->m);
|
ui->priorityList->setCurrentRow(currentIndex - 1);
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
iter_swap(switcher->functionNamesByPriority.begin() + currentIndex, switcher->functionNamesByPriority.begin() + currentIndex - 1);
|
iter_swap(switcher->functionNamesByPriority.begin() +
|
||||||
|
currentIndex,
|
||||||
|
switcher->functionNamesByPriority.begin() +
|
||||||
|
currentIndex - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_priorityDown_clicked()
|
void SceneSwitcher::on_priorityDown_clicked()
|
||||||
{
|
{
|
||||||
int currentIndex = ui->priorityList->currentRow();
|
int currentIndex = ui->priorityList->currentRow();
|
||||||
if (currentIndex != -1 && currentIndex != ui->priorityList->count() - 1)
|
if (currentIndex != -1 &&
|
||||||
{
|
currentIndex != ui->priorityList->count() - 1) {
|
||||||
ui->priorityList->insertItem(currentIndex + 1, ui->priorityList->takeItem(currentIndex));
|
ui->priorityList->insertItem(
|
||||||
|
currentIndex + 1,
|
||||||
|
ui->priorityList->takeItem(currentIndex));
|
||||||
ui->priorityList->setCurrentRow(currentIndex + 1);
|
ui->priorityList->setCurrentRow(currentIndex + 1);
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
iter_swap(switcher->functionNamesByPriority.begin() + currentIndex, switcher->functionNamesByPriority.begin() + currentIndex + 1);
|
iter_swap(switcher->functionNamesByPriority.begin() +
|
||||||
|
currentIndex,
|
||||||
|
switcher->functionNamesByPriority.begin() +
|
||||||
|
currentIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwitcherData::prioFuncsValid()
|
bool SwitcherData::prioFuncsValid()
|
||||||
{
|
{
|
||||||
auto it = std::unique(functionNamesByPriority.begin(), functionNamesByPriority.end());
|
auto it = std::unique(functionNamesByPriority.begin(),
|
||||||
|
functionNamesByPriority.end());
|
||||||
bool wasUnique = (it == functionNamesByPriority.end());
|
bool wasUnique = (it == functionNamesByPriority.end());
|
||||||
if (!wasUnique)
|
if (!wasUnique)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int p : functionNamesByPriority)
|
for (int p : functionNamesByPriority) {
|
||||||
{
|
if (p < 0 || p > 8)
|
||||||
if (p < 0 || p > 7)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
151
src/random.cpp
151
src/random.cpp
@@ -8,17 +8,16 @@ void SceneSwitcher::on_randomScenesList_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->randomScenesList->item(idx);
|
QListWidgetItem *item = ui->randomScenesList->item(idx);
|
||||||
|
|
||||||
QString randomSceneStr = item->data(Qt::UserRole).toString();
|
QString randomSceneStr = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->randomSwitches)
|
for (auto &s : switcher->randomSwitches) {
|
||||||
{
|
if (randomSceneStr.compare(s.randomSwitchStr.c_str()) == 0) {
|
||||||
if (randomSceneStr.compare(s.randomSwitchStr.c_str()) == 0)
|
|
||||||
{
|
|
||||||
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
||||||
QString transitionName = GetWeakSourceName(s.transition).c_str();
|
QString transitionName =
|
||||||
|
GetWeakSourceName(s.transition).c_str();
|
||||||
ui->randomScenes->setCurrentText(sceneName);
|
ui->randomScenes->setCurrentText(sceneName);
|
||||||
ui->randomSpinBox->setValue(s.delay);
|
ui->randomSpinBox->setValue(s.delay);
|
||||||
ui->randomTransitions->setCurrentText(transitionName);
|
ui->randomTransitions->setCurrentText(transitionName);
|
||||||
@@ -27,13 +26,12 @@ void SceneSwitcher::on_randomScenesList_currentRowChanged(int idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::randomFindByData(const QString& randomStr)
|
int SceneSwitcher::randomFindByData(const QString &randomStr)
|
||||||
{
|
{
|
||||||
int count = ui->randomScenesList->count();
|
int count = ui->randomScenesList->count();
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->randomScenesList->item(i);
|
||||||
QListWidgetItem* item = ui->randomScenesList->item(i);
|
|
||||||
QString str = item->data(Qt::UserRole).toString();
|
QString str = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (str == randomStr)
|
if (str == randomStr)
|
||||||
@@ -49,42 +47,38 @@ void SceneSwitcher::on_randomAdd_clicked()
|
|||||||
QString transitionName = ui->randomTransitions->currentText();
|
QString transitionName = ui->randomTransitions->currentText();
|
||||||
double delay = ui->randomSpinBox->value();
|
double delay = ui->randomSpinBox->value();
|
||||||
|
|
||||||
|
|
||||||
if (sceneName.isEmpty())
|
if (sceneName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
|
|
||||||
QString text = MakeRandomSwitchName(sceneName, transitionName, delay);
|
QString text = MakeRandomSwitchName(sceneName, transitionName, delay);
|
||||||
QVariant v = QVariant::fromValue(text);
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
int idx = randomFindByData(text);
|
int idx = randomFindByData(text);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
switcher->randomSwitches.emplace_back(
|
switcher->randomSwitches.emplace_back(
|
||||||
source, transition, delay, text.toUtf8().constData());
|
source, transition, delay, text.toUtf8().constData());
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->randomScenesList);
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->randomScenesList);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->randomScenesList->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->randomScenesList->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->randomSwitches)
|
for (auto &s : switcher->randomSwitches) {
|
||||||
{
|
if (s.scene == source) {
|
||||||
if (s.scene == source)
|
|
||||||
{
|
|
||||||
s.delay = delay;
|
s.delay = delay;
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.randomSwitchStr = text.toUtf8().constData();;
|
s.randomSwitchStr =
|
||||||
|
text.toUtf8().constData();
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,22 +90,21 @@ void SceneSwitcher::on_randomAdd_clicked()
|
|||||||
|
|
||||||
void SceneSwitcher::on_randomRemove_clicked()
|
void SceneSwitcher::on_randomRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->randomScenesList->currentItem();
|
QListWidgetItem *item = ui->randomScenesList->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string text = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->randomSwitches;
|
auto &switches = switcher->randomSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.randomSwitchStr == text)
|
if (s.randomSwitchStr == text) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -121,17 +114,17 @@ void SceneSwitcher::on_randomRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkRandom(bool& match, OBSWeakSource& scene, OBSWeakSource& transition, int& delay)
|
void SwitcherData::checkRandom(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition, int &delay)
|
||||||
{
|
{
|
||||||
if (randomSwitches.size() == 0)
|
if (randomSwitches.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vector<RandomSwitch> rs (randomSwitches);
|
std::vector<RandomSwitch> rs(randomSwitches);
|
||||||
std::random_device rng;
|
std::random_device rng;
|
||||||
std::mt19937 urng(rng());
|
std::mt19937 urng(rng());
|
||||||
std::shuffle(rs.begin(), rs.end(), urng);
|
std::shuffle(rs.begin(), rs.end(), urng);
|
||||||
for (RandomSwitch& r : rs)
|
for (RandomSwitch &r : rs) {
|
||||||
{
|
|
||||||
if (r.scene == lastRandomScene)
|
if (r.scene == lastRandomScene)
|
||||||
continue;
|
continue;
|
||||||
scene = r.scene;
|
scene = r.scene;
|
||||||
@@ -139,6 +132,84 @@ void SwitcherData::checkRandom(bool& match, OBSWeakSource& scene, OBSWeakSource&
|
|||||||
delay = (int)r.delay * 1000;
|
delay = (int)r.delay * 1000;
|
||||||
match = true;
|
match = true;
|
||||||
lastRandomScene = r.scene;
|
lastRandomScene = r.scene;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO, "Advanced Scene Switcher random match");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveRandomSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *randomArray = obs_data_array_create();
|
||||||
|
for (RandomSwitch &s : switcher->randomSwitches) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
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_double(array_obj, "delay", s.delay);
|
||||||
|
obs_data_set_string(array_obj, "str",
|
||||||
|
s.randomSwitchStr.c_str());
|
||||||
|
obs_data_array_push_back(randomArray, array_obj);
|
||||||
|
obs_source_release(source);
|
||||||
|
obs_source_release(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "randomSwitches", randomArray);
|
||||||
|
obs_data_array_release(randomArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadRandomSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->randomSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *randomArray =
|
||||||
|
obs_data_get_array(obj, "randomSwitches");
|
||||||
|
size_t count = obs_data_array_count(randomArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj = obs_data_array_item(randomArray, i);
|
||||||
|
|
||||||
|
const char *scene = obs_data_get_string(array_obj, "scene");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
double delay = obs_data_get_double(array_obj, "delay");
|
||||||
|
const char *str = obs_data_get_string(array_obj, "str");
|
||||||
|
|
||||||
|
switcher->randomSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition), delay, str);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(randomArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupRandomTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->randomScenes, false);
|
||||||
|
populateTransitionSelection(ui->randomTransitions);
|
||||||
|
|
||||||
|
for (auto &s : switcher->randomSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeRandomSwitchName(
|
||||||
|
sceneName.c_str(), transitionName.c_str(), s.delay);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->randomScenesList);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,50 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
|
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
#define SECONDS_INDEX 0
|
||||||
|
#define MINUTES_INDEX 1
|
||||||
|
#define HOURS_INDEX 2
|
||||||
|
|
||||||
|
void SceneSwitcher::on_sceneRoundTripDelayUnits_currentIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
double val = ui->sceneRoundTripSpinBox->value();
|
||||||
|
|
||||||
|
switch (switcher->sceneRoundTripUnitMultiplier) {
|
||||||
|
case 1:
|
||||||
|
val /= pow(60, index);
|
||||||
|
break;
|
||||||
|
case 60:
|
||||||
|
val /= pow(60, index - 1);
|
||||||
|
break;
|
||||||
|
case 3600:
|
||||||
|
val /= pow(60, index - 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->sceneRoundTripSpinBox->setValue(val);
|
||||||
|
|
||||||
|
switch (index) {
|
||||||
|
case SECONDS_INDEX:
|
||||||
|
switcher->sceneRoundTripUnitMultiplier = 1;
|
||||||
|
break;
|
||||||
|
case MINUTES_INDEX:
|
||||||
|
switcher->sceneRoundTripUnitMultiplier = 60;
|
||||||
|
break;
|
||||||
|
case HOURS_INDEX:
|
||||||
|
switcher->sceneRoundTripUnitMultiplier = 3600;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_sceneRoundTripAdd_clicked()
|
void SceneSwitcher::on_sceneRoundTripAdd_clicked()
|
||||||
{
|
{
|
||||||
QString scene1Name = ui->sceneRoundTripScenes1->currentText();
|
QString scene1Name = ui->sceneRoundTripScenes1->currentText();
|
||||||
@@ -13,7 +54,8 @@ void SceneSwitcher::on_sceneRoundTripAdd_clicked()
|
|||||||
if (scene1Name.isEmpty() || scene2Name.isEmpty())
|
if (scene1Name.isEmpty() || scene2Name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double delay = ui->sceneRoundTripSpinBox->value();
|
double delay = ui->sceneRoundTripSpinBox->value() *
|
||||||
|
switcher->sceneRoundTripUnitMultiplier;
|
||||||
|
|
||||||
if (scene1Name == scene2Name)
|
if (scene1Name == scene2Name)
|
||||||
return;
|
return;
|
||||||
@@ -22,65 +64,62 @@ void SceneSwitcher::on_sceneRoundTripAdd_clicked()
|
|||||||
OBSWeakSource source2 = GetWeakSourceByQString(scene2Name);
|
OBSWeakSource source2 = GetWeakSourceByQString(scene2Name);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
QString text = MakeSceneRoundTripSwitchName(scene1Name, scene2Name, transitionName, delay);
|
QString text = MakeSceneRoundTripSwitchName(scene1Name, scene2Name,
|
||||||
|
transitionName, delay);
|
||||||
QVariant v = QVariant::fromValue(text);
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
int idx = SceneRoundTripFindByData(scene1Name);
|
int idx = SceneRoundTripFindByData(scene1Name);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->sceneRoundTrips);
|
new QListWidgetItem(text, ui->sceneRoundTrips);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->sceneRoundTripSwitches.emplace_back(
|
switcher->sceneRoundTripSwitches.emplace_back(
|
||||||
source1, source2, transition, int(delay * 1000),
|
source1, source2, transition, delay,
|
||||||
(scene2Name == QString(PREVIOUS_SCENE_NAME)),
|
(scene2Name == QString(previous_scene_name)),
|
||||||
text.toUtf8().constData());
|
text.toUtf8().constData());
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->sceneRoundTrips->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->sceneRoundTrips->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->sceneRoundTripSwitches)
|
for (auto &s : switcher->sceneRoundTripSwitches) {
|
||||||
{
|
if (s.scene1 == source1) {
|
||||||
if (s.scene1 == source1)
|
|
||||||
{
|
|
||||||
s.scene2 = source2;
|
s.scene2 = source2;
|
||||||
s.delay = int(delay * 1000);
|
s.delay = delay;
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.usePreviousScene = (scene2Name == QString(PREVIOUS_SCENE_NAME));
|
s.usePreviousScene =
|
||||||
s.sceneRoundTripStr = text.toUtf8().constData();
|
(scene2Name ==
|
||||||
|
QString(previous_scene_name));
|
||||||
|
s.sceneRoundTripStr =
|
||||||
|
text.toUtf8().constData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->sceneRoundTrips->sortItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_sceneRoundTripRemove_clicked()
|
void SceneSwitcher::on_sceneRoundTripRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->sceneRoundTrips->currentItem();
|
QListWidgetItem *item = ui->sceneRoundTrips->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string text = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->sceneRoundTripSwitches;
|
auto &switches = switcher->sceneRoundTripSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.sceneRoundTripStr == text)
|
if (s.sceneRoundTripStr == text) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -90,149 +129,147 @@ void SceneSwitcher::on_sceneRoundTripRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_autoStopSceneCheckBox_stateChanged(int state)
|
|
||||||
{
|
|
||||||
if (loading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
if (!state)
|
|
||||||
{
|
|
||||||
ui->autoStopScenes->setDisabled(true);
|
|
||||||
switcher->autoStopEnable = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->autoStopScenes->setDisabled(false);
|
|
||||||
switcher->autoStopEnable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneSwitcher::UpdateAutoStopScene(const QString& name)
|
|
||||||
{
|
|
||||||
obs_source_t* scene = obs_get_source_by_name(name.toUtf8().constData());
|
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(scene);
|
|
||||||
|
|
||||||
switcher->autoStopScene = ws;
|
|
||||||
|
|
||||||
obs_weak_source_release(ws);
|
|
||||||
obs_source_release(scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneSwitcher::on_autoStopScenes_currentTextChanged(const QString& text)
|
|
||||||
{
|
|
||||||
if (loading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
UpdateAutoStopScene(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneSwitcher::on_sceneRoundTripSave_clicked()
|
void SceneSwitcher::on_sceneRoundTripSave_clicked()
|
||||||
{
|
{
|
||||||
QString directory = QFileDialog::getSaveFileName(
|
QString directory = QFileDialog::getSaveFileName(
|
||||||
this, tr("Save Scene Round Trip to file ..."), QDir::currentPath(), tr("Text files (*.txt)"));
|
this, tr("Save Scene Round Trip to file ..."),
|
||||||
if (!directory.isEmpty())
|
QDir::currentPath(), tr("Text files (*.txt)"));
|
||||||
{
|
if (directory.isEmpty())
|
||||||
QFile file(directory);
|
return;
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
QFile file(directory);
|
||||||
return;
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
QTextStream out(&file);
|
return;
|
||||||
for (SceneRoundTripSwitch s : switcher->sceneRoundTripSwitches)
|
|
||||||
{
|
obs_data_t *obj = obs_data_create();
|
||||||
out << QString::fromStdString(GetWeakSourceName(s.scene1)) << "\n";
|
switcher->saveSceneRoundTripSwitches(obj);
|
||||||
if (s.usePreviousScene)
|
obs_data_save_json(obj, file.fileName().toUtf8().constData());
|
||||||
out << (PREVIOUS_SCENE_NAME) << "\n";
|
obs_data_release(obj);
|
||||||
else
|
}
|
||||||
out << QString::fromStdString(GetWeakSourceName(s.scene2)) << "\n";
|
|
||||||
out << s.delay << "\n";
|
// to be removed once support for old file format is dropped
|
||||||
out << QString::fromStdString(s.sceneRoundTripStr) << "\n";
|
bool oldSceneRoundTripLoad(QFile *file)
|
||||||
out << QString::fromStdString(GetWeakSourceName(s.transition)) << "\n";
|
{
|
||||||
|
QTextStream in(file);
|
||||||
|
std::vector<QString> lines;
|
||||||
|
|
||||||
|
std::vector<SceneRoundTripSwitch> newSceneRoundTripSwitch;
|
||||||
|
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
QString line = in.readLine();
|
||||||
|
lines.push_back(line);
|
||||||
|
if (lines.size() == 5) {
|
||||||
|
OBSWeakSource scene1 = GetWeakSourceByQString(lines[0]);
|
||||||
|
OBSWeakSource scene2 = GetWeakSourceByQString(lines[1]);
|
||||||
|
OBSWeakSource transition =
|
||||||
|
GetWeakTransitionByQString(lines[4]);
|
||||||
|
|
||||||
|
if (WeakSourceValid(scene1) &&
|
||||||
|
((lines[1] == QString(previous_scene_name)) ||
|
||||||
|
(WeakSourceValid(scene2))) &&
|
||||||
|
WeakSourceValid(transition)) {
|
||||||
|
newSceneRoundTripSwitch.emplace_back(
|
||||||
|
SceneRoundTripSwitch(
|
||||||
|
GetWeakSourceByQString(lines[0]),
|
||||||
|
GetWeakSourceByQString(lines[1]),
|
||||||
|
GetWeakTransitionByQString(
|
||||||
|
lines[4]),
|
||||||
|
lines[2].toDouble() / 1000.,
|
||||||
|
(lines[1] ==
|
||||||
|
QString(previous_scene_name)),
|
||||||
|
lines[3].toStdString()));
|
||||||
|
}
|
||||||
|
lines.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lines.size() != 0 || newSceneRoundTripSwitch.size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switcher->sceneRoundTripSwitches.clear();
|
||||||
|
switcher->sceneRoundTripSwitches = newSceneRoundTripSwitch;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_sceneRoundTripLoad_clicked()
|
void SceneSwitcher::on_sceneRoundTripLoad_clicked()
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
QString directory = QFileDialog::getOpenFileName(
|
QString directory = QFileDialog::getOpenFileName(
|
||||||
this, tr("Select a file to read Scene Round Trip from ..."), QDir::currentPath(), tr("Text files (*.txt)"));
|
this, tr("Select a file to read Scene Round Trip from ..."),
|
||||||
if (!directory.isEmpty())
|
QDir::currentPath(), tr("Text files (*.txt)"));
|
||||||
{
|
if (directory.isEmpty())
|
||||||
QFile file(directory);
|
return;
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
||||||
return;
|
|
||||||
|
|
||||||
QTextStream in(&file);
|
QFile file(directory);
|
||||||
vector<QString> lines;
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
vector<SceneRoundTripSwitch> newSceneRoundTripSwitch;
|
obs_data_t *obj = obs_data_create_from_json_file(
|
||||||
|
file.fileName().toUtf8().constData());
|
||||||
|
|
||||||
while (!in.atEnd())
|
if (!obj) {
|
||||||
{
|
QMessageBox Msgbox;
|
||||||
QString line = in.readLine();
|
QString txt =
|
||||||
lines.push_back(line);
|
"Advanced Scene Switcher failed to import settings!\n";
|
||||||
if (lines.size() == 5)
|
txt += "Falling back to old format.";
|
||||||
{
|
Msgbox.setText(txt);
|
||||||
OBSWeakSource scene1 = GetWeakSourceByQString(lines[0]);
|
Msgbox.exec();
|
||||||
OBSWeakSource scene2 = GetWeakSourceByQString(lines[1]);
|
if (oldSceneRoundTripLoad(&file)) {
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(lines[4]);
|
QString txt =
|
||||||
|
"Advanced Scene Switcher settings imported successfully!\n";
|
||||||
if (WeakSourceValid(scene1) && ((lines[1] == QString(PREVIOUS_SCENE_NAME)) || (WeakSourceValid(scene2)))
|
txt += "Please resave settings as support for old format will be dropped in next version.";
|
||||||
&& WeakSourceValid(transition))
|
Msgbox.setText(txt);
|
||||||
{
|
Msgbox.exec();
|
||||||
newSceneRoundTripSwitch.emplace_back(SceneRoundTripSwitch(
|
close();
|
||||||
GetWeakSourceByQString(lines[0]),
|
} else {
|
||||||
GetWeakSourceByQString(lines[1]),
|
Msgbox.setText(
|
||||||
GetWeakTransitionByQString(lines[4]),
|
"Advanced Scene Switcher failed to import settings!");
|
||||||
lines[2].toInt(),
|
Msgbox.exec();
|
||||||
(lines[1] == QString(PREVIOUS_SCENE_NAME)),
|
|
||||||
lines[3].toStdString()));
|
|
||||||
}
|
|
||||||
lines.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lines.size() != 0 || newSceneRoundTripSwitch.size() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switcher->sceneRoundTripSwitches.clear();
|
|
||||||
ui->sceneRoundTrips->clear();
|
|
||||||
switcher->sceneRoundTripSwitches = newSceneRoundTripSwitch;
|
|
||||||
for (SceneRoundTripSwitch s : switcher->sceneRoundTripSwitches)
|
|
||||||
{
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(s.sceneRoundTripStr), ui->sceneRoundTrips);
|
|
||||||
item->setData(Qt::UserRole, QString::fromStdString(s.sceneRoundTripStr));
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
switcher->loadSceneRoundTripSwitches(obj);
|
||||||
|
obs_data_release(obj);
|
||||||
|
|
||||||
|
QMessageBox Msgbox;
|
||||||
|
Msgbox.setText(
|
||||||
|
"Advanced Scene Switcher settings imported successfully!");
|
||||||
|
Msgbox.exec();
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::checkSceneRoundTrip(bool &match, OBSWeakSource &scene,
|
||||||
void SwitcherData::checkSceneRoundTrip(bool& match, OBSWeakSource& scene, OBSWeakSource& transition, unique_lock<mutex>& lock)
|
OBSWeakSource &transition,
|
||||||
|
std::unique_lock<std::mutex> &lock)
|
||||||
{
|
{
|
||||||
bool sceneRoundTripActive = false;
|
bool sceneRoundTripActive = false;
|
||||||
obs_source_t* currentSource = obs_frontend_get_current_scene();
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(currentSource);
|
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
|
||||||
|
|
||||||
for (SceneRoundTripSwitch& s : sceneRoundTripSwitches)
|
for (SceneRoundTripSwitch &s : sceneRoundTripSwitches) {
|
||||||
{
|
if (s.scene1 == ws) {
|
||||||
if (s.scene1 == ws)
|
|
||||||
{
|
|
||||||
sceneRoundTripActive = true;
|
sceneRoundTripActive = true;
|
||||||
int dur = s.delay - interval;
|
int dur = s.delay * 1000 - interval;
|
||||||
if (dur > 0)
|
if (dur > 0) {
|
||||||
{
|
|
||||||
waitScene = currentSource;
|
waitScene = currentSource;
|
||||||
cv.wait_for(lock, chrono::milliseconds(dur));
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher sequence sleep %d",
|
||||||
|
dur);
|
||||||
|
|
||||||
|
cv.wait_for(lock,
|
||||||
|
std::chrono::milliseconds(dur));
|
||||||
|
waitScene = nullptr;
|
||||||
}
|
}
|
||||||
obs_source_t* currentSource2 = obs_frontend_get_current_scene();
|
obs_source_t *currentSource2 =
|
||||||
|
obs_frontend_get_current_scene();
|
||||||
|
|
||||||
// only switch if user hasn't changed scene manually
|
// only switch if user hasn't changed scene manually
|
||||||
if (currentSource == currentSource2)
|
if (currentSource == currentSource2) {
|
||||||
{
|
|
||||||
match = true;
|
match = true;
|
||||||
scene = (s.usePreviousScene) ? previousScene : s.scene2;
|
scene = (s.usePreviousScene) ? previousScene
|
||||||
|
: s.scene2;
|
||||||
transition = s.transition;
|
transition = s.transition;
|
||||||
}
|
}
|
||||||
obs_source_release(currentSource2);
|
obs_source_release(currentSource2);
|
||||||
@@ -250,42 +287,42 @@ void SceneSwitcher::on_sceneRoundTrips_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->sceneRoundTrips->item(idx);
|
QListWidgetItem *item = ui->sceneRoundTrips->item(idx);
|
||||||
|
|
||||||
QString sceneRoundTrip = item->text();
|
QString sceneRoundTrip = item->text();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->sceneRoundTripSwitches)
|
for (auto &s : switcher->sceneRoundTripSwitches) {
|
||||||
{
|
if (sceneRoundTrip.compare(s.sceneRoundTripStr.c_str()) == 0) {
|
||||||
if (sceneRoundTrip.compare(s.sceneRoundTripStr.c_str()) == 0)
|
std::string scene1 = GetWeakSourceName(s.scene1);
|
||||||
{
|
std::string scene2 = GetWeakSourceName(s.scene2);
|
||||||
string scene1 = GetWeakSourceName(s.scene1);
|
std::string transitionName =
|
||||||
string scene2 = GetWeakSourceName(s.scene2);
|
GetWeakSourceName(s.transition);
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
double delay = s.delay /
|
||||||
int delay = s.delay;
|
switcher->sceneRoundTripUnitMultiplier;
|
||||||
ui->sceneRoundTripScenes1->setCurrentText(scene1.c_str());
|
ui->sceneRoundTripScenes1->setCurrentText(
|
||||||
ui->sceneRoundTripScenes2->setCurrentText(scene2.c_str());
|
scene1.c_str());
|
||||||
ui->sceneRoundTripTransitions->setCurrentText(transitionName.c_str());
|
ui->sceneRoundTripScenes2->setCurrentText(
|
||||||
ui->sceneRoundTripSpinBox->setValue((double)delay/1000);
|
scene2.c_str());
|
||||||
|
ui->sceneRoundTripTransitions->setCurrentText(
|
||||||
|
transitionName.c_str());
|
||||||
|
ui->sceneRoundTripSpinBox->setValue(delay);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SceneSwitcher::SceneRoundTripFindByData(const QString &scene1)
|
||||||
int SceneSwitcher::SceneRoundTripFindByData(const QString& scene1)
|
|
||||||
{
|
{
|
||||||
QRegExp rx(scene1 + " ->.*");
|
QRegExp rx(scene1 + " ->.*");
|
||||||
int count = ui->sceneRoundTrips->count();
|
int count = ui->sceneRoundTrips->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->sceneRoundTrips->item(i);
|
||||||
QListWidgetItem* item = ui->sceneRoundTrips->item(i);
|
|
||||||
QString itemString = item->data(Qt::UserRole).toString();
|
QString itemString = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (rx.exactMatch(itemString))
|
if (rx.exactMatch(itemString)) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -294,19 +331,170 @@ int SceneSwitcher::SceneRoundTripFindByData(const QString& scene1)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_sceneRoundTripUp_clicked()
|
||||||
void SwitcherData::autoStopStreamAndRecording()
|
|
||||||
{
|
{
|
||||||
obs_source_t* currentSource = obs_frontend_get_current_scene();
|
int index = ui->sceneRoundTrips->currentRow();
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(currentSource);
|
if (index != -1 && index != 0) {
|
||||||
|
ui->sceneRoundTrips->insertItem(
|
||||||
|
index - 1, ui->sceneRoundTrips->takeItem(index));
|
||||||
|
ui->sceneRoundTrips->setCurrentRow(index - 1);
|
||||||
|
|
||||||
if (ws && autoStopScene == ws)
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
{
|
|
||||||
if (obs_frontend_streaming_active())
|
iter_swap(switcher->sceneRoundTripSwitches.begin() + index,
|
||||||
obs_frontend_streaming_stop();
|
switcher->sceneRoundTripSwitches.begin() + index - 1);
|
||||||
if (obs_frontend_recording_active())
|
}
|
||||||
obs_frontend_recording_stop();
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_sceneRoundTripDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->sceneRoundTrips->currentRow();
|
||||||
|
if (index != -1 && index != ui->sceneRoundTrips->count() - 1) {
|
||||||
|
ui->sceneRoundTrips->insertItem(
|
||||||
|
index + 1, ui->sceneRoundTrips->takeItem(index));
|
||||||
|
ui->sceneRoundTrips->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->sceneRoundTripSwitches.begin() + index,
|
||||||
|
switcher->sceneRoundTripSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveSceneRoundTripSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *sceneRoundTripArray = obs_data_array_create();
|
||||||
|
for (SceneRoundTripSwitch &s : switcher->sceneRoundTripSwitches) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
|
||||||
|
obs_source_t *source1 = obs_weak_source_get_source(s.scene1);
|
||||||
|
obs_source_t *source2 = obs_weak_source_get_source(s.scene2);
|
||||||
|
obs_source_t *transition =
|
||||||
|
obs_weak_source_get_source(s.transition);
|
||||||
|
if (source1 && (s.usePreviousScene || source2) && transition) {
|
||||||
|
const char *sceneName1 = obs_source_get_name(source1);
|
||||||
|
const char *sceneName2 = obs_source_get_name(source2);
|
||||||
|
const char *transitionName =
|
||||||
|
obs_source_get_name(transition);
|
||||||
|
obs_data_set_string(array_obj, "sceneRoundTripScene1",
|
||||||
|
sceneName1);
|
||||||
|
obs_data_set_string(array_obj, "sceneRoundTripScene2",
|
||||||
|
s.usePreviousScene
|
||||||
|
? previous_scene_name
|
||||||
|
: sceneName2);
|
||||||
|
obs_data_set_string(array_obj, "transition",
|
||||||
|
transitionName);
|
||||||
|
obs_data_set_double(array_obj, "delay", s.delay);
|
||||||
|
obs_data_set_string(array_obj, "sceneRoundTripStr",
|
||||||
|
s.sceneRoundTripStr.c_str());
|
||||||
|
obs_data_array_push_back(sceneRoundTripArray,
|
||||||
|
array_obj);
|
||||||
|
obs_source_release(source1);
|
||||||
|
obs_source_release(source2);
|
||||||
|
obs_source_release(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "sceneRoundTrip", sceneRoundTripArray);
|
||||||
|
obs_data_array_release(sceneRoundTripArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadSceneRoundTripSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->sceneRoundTripSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *sceneRoundTripArray =
|
||||||
|
obs_data_get_array(obj, "sceneRoundTrip");
|
||||||
|
size_t count = obs_data_array_count(sceneRoundTripArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(sceneRoundTripArray, i);
|
||||||
|
|
||||||
|
const char *scene1 =
|
||||||
|
obs_data_get_string(array_obj, "sceneRoundTripScene1");
|
||||||
|
const char *scene2 =
|
||||||
|
obs_data_get_string(array_obj, "sceneRoundTripScene2");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
|
||||||
|
double delay = 0;
|
||||||
|
|
||||||
|
// To be removed in future version
|
||||||
|
// to be compatible with older versions
|
||||||
|
if (!obs_data_has_user_value(array_obj, "delay")) {
|
||||||
|
delay = double(obs_data_get_int(array_obj,
|
||||||
|
"sceneRoundTripDelay"));
|
||||||
|
delay = delay * 1000. +
|
||||||
|
double(obs_data_get_int(
|
||||||
|
array_obj, "sceneRoundTripDelayMs"));
|
||||||
|
delay /= 1000.;
|
||||||
|
} else {
|
||||||
|
delay = obs_data_get_double(array_obj, "delay");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string str = MakeSceneRoundTripSwitchName(
|
||||||
|
scene1, scene2, transition, delay)
|
||||||
|
.toUtf8()
|
||||||
|
.constData();
|
||||||
|
const char *sceneRoundTripStr = str.c_str();
|
||||||
|
|
||||||
|
switcher->sceneRoundTripSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene1),
|
||||||
|
GetWeakSourceByName(scene2),
|
||||||
|
GetWeakTransitionByName(transition), delay,
|
||||||
|
(strcmp(scene2, previous_scene_name) == 0),
|
||||||
|
sceneRoundTripStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(sceneRoundTripArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupSequenceTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->sceneRoundTripScenes1, false);
|
||||||
|
populateSceneSelection(ui->sceneRoundTripScenes2, true);
|
||||||
|
populateTransitionSelection(ui->sceneRoundTripTransitions);
|
||||||
|
|
||||||
|
double smallestDelay = double(switcher->interval) / 1000;
|
||||||
|
for (auto &s : switcher->sceneRoundTripSwitches) {
|
||||||
|
std::string sceneName1 = GetWeakSourceName(s.scene1);
|
||||||
|
std::string sceneName2 = (s.usePreviousScene)
|
||||||
|
? previous_scene_name
|
||||||
|
: GetWeakSourceName(s.scene2);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeSceneRoundTripSwitchName(
|
||||||
|
sceneName1.c_str(), sceneName2.c_str(),
|
||||||
|
transitionName.c_str(), s.delay);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->sceneRoundTrips);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
|
||||||
|
if (s.delay < smallestDelay)
|
||||||
|
smallestDelay = s.delay;
|
||||||
|
}
|
||||||
|
(smallestDelay * 1000 < switcher->interval)
|
||||||
|
? ui->intervalWarning->setVisible(true)
|
||||||
|
: ui->intervalWarning->setVisible(false);
|
||||||
|
|
||||||
|
ui->sceneRoundTripDelayUnits->addItem("seconds");
|
||||||
|
ui->sceneRoundTripDelayUnits->addItem("minutes");
|
||||||
|
ui->sceneRoundTripDelayUnits->addItem("hours");
|
||||||
|
|
||||||
|
switch (switcher->sceneRoundTripUnitMultiplier) {
|
||||||
|
case 1:
|
||||||
|
ui->sceneRoundTripDelayUnits->setCurrentIndex(0);
|
||||||
|
break;
|
||||||
|
case 60:
|
||||||
|
ui->sceneRoundTripDelayUnits->setCurrentIndex(1);
|
||||||
|
break;
|
||||||
|
case 3600:
|
||||||
|
ui->sceneRoundTripDelayUnits->setCurrentIndex(2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
obs_source_release(currentSource);
|
|
||||||
obs_weak_source_release(ws);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,33 +16,33 @@ void SceneSwitcher::on_transitionsAdd_clicked()
|
|||||||
OBSWeakSource source2 = GetWeakSourceByQString(scene2Name);
|
OBSWeakSource source2 = GetWeakSourceByQString(scene2Name);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
QString text = MakeSceneTransitionName(scene1Name, scene2Name, transitionName);
|
QString text =
|
||||||
|
MakeSceneTransitionName(scene1Name, scene2Name, transitionName);
|
||||||
QVariant v = QVariant::fromValue(text);
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
int idx = SceneTransitionsFindByData(scene1Name, scene2Name);
|
int idx = SceneTransitionsFindByData(scene1Name, scene2Name);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->sceneTransitions);
|
new QListWidgetItem(text, ui->sceneTransitions);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->sceneTransitions.emplace_back(
|
switcher->sceneTransitions.emplace_back(
|
||||||
source1, source2, transition, text.toUtf8().constData());
|
source1, source2, transition,
|
||||||
}
|
text.toUtf8().constData());
|
||||||
else
|
} else {
|
||||||
{
|
QListWidgetItem *item = ui->sceneTransitions->item(idx);
|
||||||
QListWidgetItem* item = ui->sceneTransitions->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->sceneTransitions)
|
for (auto &s : switcher->sceneTransitions) {
|
||||||
{
|
if (s.scene1 == source1 &&
|
||||||
if (s.scene1 == source1 && s.scene2 == source2)
|
s.scene2 == source2) {
|
||||||
{
|
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.sceneTransitionStr = text.toUtf8().constData();
|
s.sceneTransitionStr =
|
||||||
|
text.toUtf8().constData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,22 +54,21 @@ void SceneSwitcher::on_transitionsAdd_clicked()
|
|||||||
|
|
||||||
void SceneSwitcher::on_transitionsRemove_clicked()
|
void SceneSwitcher::on_transitionsRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->sceneTransitions->currentItem();
|
QListWidgetItem *item = ui->sceneTransitions->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string text = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->sceneTransitions;
|
auto &switches = switcher->sceneTransitions;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.sceneTransitionStr == text)
|
if (s.sceneTransitionStr == text) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -82,7 +81,8 @@ void SceneSwitcher::on_transitionsRemove_clicked()
|
|||||||
void SceneSwitcher::on_defaultTransitionsAdd_clicked()
|
void SceneSwitcher::on_defaultTransitionsAdd_clicked()
|
||||||
{
|
{
|
||||||
QString sceneName = ui->defaultTransitionsScene->currentText();
|
QString sceneName = ui->defaultTransitionsScene->currentText();
|
||||||
QString transitionName = ui->defaultTransitionsTransitions->currentText();
|
QString transitionName =
|
||||||
|
ui->defaultTransitionsTransitions->currentText();
|
||||||
|
|
||||||
if (sceneName.isEmpty() || transitionName.isEmpty())
|
if (sceneName.isEmpty() || transitionName.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -90,33 +90,31 @@ void SceneSwitcher::on_defaultTransitionsAdd_clicked()
|
|||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
QString text = MakeDefaultSceneTransitionName(sceneName, transitionName);
|
QString text =
|
||||||
|
MakeDefaultSceneTransitionName(sceneName, transitionName);
|
||||||
QVariant v = QVariant::fromValue(text);
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
int idx = DefaultTransitionsFindByData(sceneName);
|
int idx = DefaultTransitionsFindByData(sceneName);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->defaultTransitions);
|
new QListWidgetItem(text, ui->defaultTransitions);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->defaultSceneTransitions.emplace_back(
|
switcher->defaultSceneTransitions.emplace_back(
|
||||||
source, transition, text.toUtf8().constData());
|
source, transition, text.toUtf8().constData());
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->defaultTransitions->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->defaultTransitions->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->defaultSceneTransitions)
|
for (auto &s : switcher->defaultSceneTransitions) {
|
||||||
{
|
if (s.scene == source) {
|
||||||
if (s.scene == source)
|
|
||||||
{
|
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.sceneTransitionStr = text.toUtf8().constData();
|
s.sceneTransitionStr =
|
||||||
|
text.toUtf8().constData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,22 +126,21 @@ void SceneSwitcher::on_defaultTransitionsAdd_clicked()
|
|||||||
|
|
||||||
void SceneSwitcher::on_defaultTransitionsRemove_clicked()
|
void SceneSwitcher::on_defaultTransitionsRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->defaultTransitions->currentItem();
|
QListWidgetItem *item = ui->defaultTransitions->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string text = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->defaultSceneTransitions;
|
auto &switches = switcher->defaultSceneTransitions;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.sceneTransitionStr == text)
|
if (s.sceneTransitionStr == text) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -155,17 +152,21 @@ void SceneSwitcher::on_defaultTransitionsRemove_clicked()
|
|||||||
|
|
||||||
void SwitcherData::setDefaultSceneTransitions()
|
void SwitcherData::setDefaultSceneTransitions()
|
||||||
{
|
{
|
||||||
obs_source_t* currentSource = obs_frontend_get_current_scene();
|
obs_source_t *currentSource = obs_frontend_get_current_scene();
|
||||||
obs_weak_source_t* ws = obs_source_get_weak_source(currentSource);
|
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
|
||||||
|
|
||||||
for (DefaultSceneTransition& s : defaultSceneTransitions)
|
for (DefaultSceneTransition &s : defaultSceneTransitions) {
|
||||||
{
|
if (s.scene == ws) {
|
||||||
if (s.scene == ws)
|
obs_source_t *transition =
|
||||||
{
|
obs_weak_source_get_source(s.transition);
|
||||||
obs_source_t* transition = obs_weak_source_get_source(s.transition);
|
|
||||||
//This might cancel the current transition
|
//This might cancel the current transition
|
||||||
//There is no way to be sure when the previous transition finished
|
//There is no way to be sure when the previous transition finished
|
||||||
obs_frontend_set_current_transition(transition);
|
obs_frontend_set_current_transition(transition);
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher default transition set");
|
||||||
|
|
||||||
obs_source_release(transition);
|
obs_source_release(transition);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -174,19 +175,18 @@ void SwitcherData::setDefaultSceneTransitions()
|
|||||||
obs_weak_source_release(ws);
|
obs_weak_source_release(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::SceneTransitionsFindByData(const QString& scene1, const QString& scene2)
|
int SceneSwitcher::SceneTransitionsFindByData(const QString &scene1,
|
||||||
|
const QString &scene2)
|
||||||
{
|
{
|
||||||
QRegExp rx(scene1 + " --- .* --> " + scene2);
|
QRegExp rx(scene1 + " --- .* --> " + scene2);
|
||||||
int count = ui->sceneTransitions->count();
|
int count = ui->sceneTransitions->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->sceneTransitions->item(i);
|
||||||
QListWidgetItem* item = ui->sceneTransitions->item(i);
|
|
||||||
QString itemString = item->data(Qt::UserRole).toString();
|
QString itemString = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (rx.exactMatch(itemString))
|
if (rx.exactMatch(itemString)) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -195,19 +195,17 @@ int SceneSwitcher::SceneTransitionsFindByData(const QString& scene1, const QStri
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::DefaultTransitionsFindByData(const QString& scene)
|
int SceneSwitcher::DefaultTransitionsFindByData(const QString &scene)
|
||||||
{
|
{
|
||||||
QRegExp rx(scene + " --> .*");
|
QRegExp rx(scene + " --> .*");
|
||||||
int count = ui->defaultTransitions->count();
|
int count = ui->defaultTransitions->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->defaultTransitions->item(i);
|
||||||
QListWidgetItem* item = ui->defaultTransitions->item(i);
|
|
||||||
QString itemString = item->data(Qt::UserRole).toString();
|
QString itemString = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (rx.exactMatch(itemString))
|
if (rx.exactMatch(itemString)) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -223,21 +221,22 @@ void SceneSwitcher::on_sceneTransitions_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->sceneTransitions->item(idx);
|
QListWidgetItem *item = ui->sceneTransitions->item(idx);
|
||||||
|
|
||||||
QString sceneTransition = item->data(Qt::UserRole).toString();
|
QString sceneTransition = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->sceneTransitions)
|
for (auto &s : switcher->sceneTransitions) {
|
||||||
{
|
if (sceneTransition.compare(s.sceneTransitionStr.c_str()) ==
|
||||||
if (sceneTransition.compare(s.sceneTransitionStr.c_str()) == 0)
|
0) {
|
||||||
{
|
std::string scene1 = GetWeakSourceName(s.scene1);
|
||||||
string scene1 = GetWeakSourceName(s.scene1);
|
std::string scene2 = GetWeakSourceName(s.scene2);
|
||||||
string scene2 = GetWeakSourceName(s.scene2);
|
std::string transitionName =
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
GetWeakSourceName(s.transition);
|
||||||
ui->transitionsScene1->setCurrentText(scene1.c_str());
|
ui->transitionsScene1->setCurrentText(scene1.c_str());
|
||||||
ui->transitionsScene2->setCurrentText(scene2.c_str());
|
ui->transitionsScene2->setCurrentText(scene2.c_str());
|
||||||
ui->transitionsTransitions->setCurrentText(transitionName.c_str());
|
ui->transitionsTransitions->setCurrentText(
|
||||||
|
transitionName.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,31 +249,45 @@ void SceneSwitcher::on_defaultTransitions_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->defaultTransitions->item(idx);
|
QListWidgetItem *item = ui->defaultTransitions->item(idx);
|
||||||
|
|
||||||
QString sceneTransition = item->data(Qt::UserRole).toString();
|
QString sceneTransition = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->defaultSceneTransitions)
|
for (auto &s : switcher->defaultSceneTransitions) {
|
||||||
{
|
if (sceneTransition.compare(s.sceneTransitionStr.c_str()) ==
|
||||||
if (sceneTransition.compare(s.sceneTransitionStr.c_str()) == 0)
|
0) {
|
||||||
{
|
std::string scene = GetWeakSourceName(s.scene);
|
||||||
string scene = GetWeakSourceName(s.scene);
|
std::string transitionName =
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
GetWeakSourceName(s.transition);
|
||||||
ui->defaultTransitionsScene->setCurrentText(scene.c_str());
|
ui->defaultTransitionsScene->setCurrentText(
|
||||||
ui->defaultTransitionsTransitions->setCurrentText(transitionName.c_str());
|
scene.c_str());
|
||||||
|
ui->defaultTransitionsTransitions->setCurrentText(
|
||||||
|
transitionName.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_weak_source_t* getNextTransition(obs_weak_source_t* scene1, obs_weak_source_t* scene2)
|
void SceneSwitcher::on_transitionOverridecheckBox_stateChanged(int state)
|
||||||
{
|
{
|
||||||
obs_weak_source_t* ws = nullptr;
|
if (loading)
|
||||||
if (scene1 && scene2)
|
return;
|
||||||
{
|
|
||||||
for (SceneTransition& t : switcher->sceneTransitions)
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
{
|
if (!state) {
|
||||||
|
switcher->tansitionOverrideOverride = false;
|
||||||
|
} else {
|
||||||
|
switcher->tansitionOverrideOverride = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_weak_source_t *getNextTransition(obs_weak_source_t *scene1,
|
||||||
|
obs_weak_source_t *scene2)
|
||||||
|
{
|
||||||
|
obs_weak_source_t *ws = nullptr;
|
||||||
|
if (scene1 && scene2) {
|
||||||
|
for (SceneTransition &t : switcher->sceneTransitions) {
|
||||||
if (t.scene1 == scene1 && t.scene2 == scene2)
|
if (t.scene1 == scene1 && t.scene2 == scene2)
|
||||||
ws = t.transition;
|
ws = t.transition;
|
||||||
}
|
}
|
||||||
@@ -282,3 +295,221 @@ obs_weak_source_t* getNextTransition(obs_weak_source_t* scene1, obs_weak_source_
|
|||||||
}
|
}
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void overwriteTransitionOverride(obs_weak_source_t *sceneWs,
|
||||||
|
obs_source_t *transition, transitionData &td)
|
||||||
|
{
|
||||||
|
obs_source_t *scene = obs_weak_source_get_source(sceneWs);
|
||||||
|
obs_data_t *data = obs_source_get_private_settings(scene);
|
||||||
|
|
||||||
|
td.name = obs_data_get_string(data, "transition");
|
||||||
|
td.duration = obs_data_get_int(data, "duration");
|
||||||
|
|
||||||
|
const char *name = obs_source_get_name(transition);
|
||||||
|
int duration = obs_frontend_get_transition_duration();
|
||||||
|
|
||||||
|
obs_data_set_string(data, "transition", name);
|
||||||
|
obs_data_set_int(data, "transition_duration", duration);
|
||||||
|
|
||||||
|
obs_data_release(data);
|
||||||
|
obs_source_release(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
void restoreTransitionOverride(obs_source_t *scene, transitionData td)
|
||||||
|
{
|
||||||
|
obs_data_t *data = obs_source_get_private_settings(scene);
|
||||||
|
|
||||||
|
obs_data_set_string(data, "transition", td.name.c_str());
|
||||||
|
obs_data_set_int(data, "transition_duration", td.duration);
|
||||||
|
|
||||||
|
obs_data_release(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNextTransition(OBSWeakSource &targetScene, obs_source_t *currentSource,
|
||||||
|
OBSWeakSource &transition,
|
||||||
|
bool &transitionOverrideOverride, transitionData &td)
|
||||||
|
{
|
||||||
|
obs_weak_source_t *currentScene =
|
||||||
|
obs_source_get_weak_source(currentSource);
|
||||||
|
obs_weak_source_t *nextTransitionWs =
|
||||||
|
getNextTransition(currentScene, targetScene);
|
||||||
|
obs_weak_source_release(currentScene);
|
||||||
|
|
||||||
|
obs_source_t *nextTransition = nullptr;
|
||||||
|
if (nextTransitionWs) {
|
||||||
|
nextTransition = obs_weak_source_get_source(nextTransitionWs);
|
||||||
|
} else if (transition) {
|
||||||
|
nextTransition = obs_weak_source_get_source(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextTransition) {
|
||||||
|
obs_frontend_set_current_transition(nextTransition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transitionOverrideOverride)
|
||||||
|
overwriteTransitionOverride(targetScene, nextTransition, td);
|
||||||
|
|
||||||
|
obs_weak_source_release(nextTransitionWs);
|
||||||
|
obs_source_release(nextTransition);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveSceneTransitions(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *sceneTransitionsArray = obs_data_array_create();
|
||||||
|
for (SceneTransition &s : switcher->sceneTransitions) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
|
||||||
|
obs_source_t *source1 = obs_weak_source_get_source(s.scene1);
|
||||||
|
obs_source_t *source2 = obs_weak_source_get_source(s.scene2);
|
||||||
|
obs_source_t *transition =
|
||||||
|
obs_weak_source_get_source(s.transition);
|
||||||
|
if (source1 && source2 && transition) {
|
||||||
|
const char *sceneName1 = obs_source_get_name(source1);
|
||||||
|
const char *sceneName2 = obs_source_get_name(source2);
|
||||||
|
const char *transitionName =
|
||||||
|
obs_source_get_name(transition);
|
||||||
|
obs_data_set_string(array_obj, "Scene1", sceneName1);
|
||||||
|
obs_data_set_string(array_obj, "Scene2", sceneName2);
|
||||||
|
obs_data_set_string(array_obj, "transition",
|
||||||
|
transitionName);
|
||||||
|
obs_data_set_string(array_obj, "Str",
|
||||||
|
s.sceneTransitionStr.c_str());
|
||||||
|
obs_data_array_push_back(sceneTransitionsArray,
|
||||||
|
array_obj);
|
||||||
|
obs_source_release(source1);
|
||||||
|
obs_source_release(source2);
|
||||||
|
obs_source_release(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "sceneTransitions", sceneTransitionsArray);
|
||||||
|
obs_data_array_release(sceneTransitionsArray);
|
||||||
|
|
||||||
|
obs_data_array_t *defaultTransitionsArray = obs_data_array_create();
|
||||||
|
for (DefaultSceneTransition &s : switcher->defaultSceneTransitions) {
|
||||||
|
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);
|
||||||
|
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, "Str",
|
||||||
|
s.sceneTransitionStr.c_str());
|
||||||
|
obs_data_array_push_back(defaultTransitionsArray,
|
||||||
|
array_obj);
|
||||||
|
obs_source_release(source);
|
||||||
|
obs_source_release(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "defaultTransitions", defaultTransitionsArray);
|
||||||
|
obs_data_array_release(defaultTransitionsArray);
|
||||||
|
|
||||||
|
obs_data_set_bool(obj, "tansitionOverrideOverride",
|
||||||
|
switcher->tansitionOverrideOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadSceneTransitions(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->sceneTransitions.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *sceneTransitionsArray =
|
||||||
|
obs_data_get_array(obj, "sceneTransitions");
|
||||||
|
size_t count = obs_data_array_count(sceneTransitionsArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(sceneTransitionsArray, i);
|
||||||
|
|
||||||
|
const char *scene1 = obs_data_get_string(array_obj, "Scene1");
|
||||||
|
const char *scene2 = obs_data_get_string(array_obj, "Scene2");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
const char *sceneTransitionsStr =
|
||||||
|
obs_data_get_string(array_obj, "Str");
|
||||||
|
|
||||||
|
switcher->sceneTransitions.emplace_back(
|
||||||
|
GetWeakSourceByName(scene1),
|
||||||
|
GetWeakSourceByName(scene2),
|
||||||
|
GetWeakTransitionByName(transition),
|
||||||
|
sceneTransitionsStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(sceneTransitionsArray);
|
||||||
|
|
||||||
|
switcher->defaultSceneTransitions.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *defaultTransitionsArray =
|
||||||
|
obs_data_get_array(obj, "defaultTransitions");
|
||||||
|
count = obs_data_array_count(defaultTransitionsArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(defaultTransitionsArray, i);
|
||||||
|
|
||||||
|
const char *scene = obs_data_get_string(array_obj, "Scene");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
const char *sceneTransitionsStr =
|
||||||
|
obs_data_get_string(array_obj, "Str");
|
||||||
|
|
||||||
|
switcher->defaultSceneTransitions.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition),
|
||||||
|
sceneTransitionsStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(defaultTransitionsArray);
|
||||||
|
|
||||||
|
switcher->tansitionOverrideOverride =
|
||||||
|
obs_data_get_bool(obj, "tansitionOverrideOverride");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupTransitionsTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->transitionsScene1, false);
|
||||||
|
populateSceneSelection(ui->transitionsScene2, false);
|
||||||
|
populateSceneSelection(ui->defaultTransitionsScene, false);
|
||||||
|
populateTransitionSelection(ui->transitionsTransitions);
|
||||||
|
populateTransitionSelection(ui->defaultTransitionsTransitions);
|
||||||
|
|
||||||
|
for (auto &s : switcher->sceneTransitions) {
|
||||||
|
std::string sceneName1 = GetWeakSourceName(s.scene1);
|
||||||
|
std::string sceneName2 = GetWeakSourceName(s.scene2);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeSceneTransitionName(sceneName1.c_str(),
|
||||||
|
sceneName2.c_str(),
|
||||||
|
transitionName.c_str());
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->sceneTransitions);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
//(transitionDurationLongerThanInterval(switcher->interval))
|
||||||
|
// ? ui->transitionWarning->setVisible(true)
|
||||||
|
// : ui->transitionWarning->setVisible(false);
|
||||||
|
|
||||||
|
for (auto &s : switcher->defaultSceneTransitions) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeDefaultSceneTransitionName(
|
||||||
|
sceneName.c_str(), transitionName.c_str());
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->defaultTransitions);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->transitionOverridecheckBox->setChecked(
|
||||||
|
switcher->tansitionOverrideOverride);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
void SwitcherData::checkScreenRegionSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
void SwitcherData::checkScreenRegionSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
pair<int, int> cursorPos = getCursorPos();
|
std::pair<int, int> cursorPos = getCursorPos();
|
||||||
int minRegionSize = 99999;
|
int minRegionSize = 99999;
|
||||||
|
|
||||||
for (auto& s : screenRegionSwitches)
|
for (auto &s : screenRegionSwitches) {
|
||||||
{
|
if (cursorPos.first >= s.minX && cursorPos.second >= s.minY &&
|
||||||
if (cursorPos.first >= s.minX && cursorPos.second >= s.minY
|
cursorPos.first <= s.maxX && cursorPos.second <= s.maxY) {
|
||||||
&& cursorPos.first <= s.maxX && cursorPos.second <= s.maxY)
|
|
||||||
{
|
|
||||||
int regionSize = (s.maxX - s.minX) + (s.maxY - s.minY);
|
int regionSize = (s.maxX - s.minX) + (s.maxY - s.minY);
|
||||||
if (regionSize < minRegionSize)
|
if (regionSize < minRegionSize) {
|
||||||
{
|
|
||||||
match = true;
|
match = true;
|
||||||
scene = s.scene;
|
scene = s.scene;
|
||||||
transition = s.transition;
|
transition = s.transition;
|
||||||
minRegionSize = regionSize;
|
minRegionSize = regionSize;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher region match");
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,9 +30,8 @@ void SwitcherData::checkScreenRegionSwitch(bool& match, OBSWeakSource& scene, OB
|
|||||||
|
|
||||||
void SceneSwitcher::updateScreenRegionCursorPos()
|
void SceneSwitcher::updateScreenRegionCursorPos()
|
||||||
{
|
{
|
||||||
pair<int, int> position = getCursorPos();
|
std::pair<int, int> position = getCursorPos();
|
||||||
ui->cursorXPosition->setText(QString::number(position.first));
|
ui->cursorXPosition->setText(QString::number(position.first));
|
||||||
;
|
|
||||||
ui->cursorYPosition->setText(QString::number(position.second));
|
ui->cursorYPosition->setText(QString::number(position.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,69 +48,64 @@ void SceneSwitcher::on_screenRegionAdd_clicked()
|
|||||||
int maxX = ui->screenRegionMaxX->value();
|
int maxX = ui->screenRegionMaxX->value();
|
||||||
int maxY = ui->screenRegionMaxY->value();
|
int maxY = ui->screenRegionMaxY->value();
|
||||||
|
|
||||||
string regionStr = to_string(minX) + ", " + to_string(minY) + " x " + to_string(maxX) + ", "
|
std::string regionStr =
|
||||||
+ to_string(maxY);
|
std::to_string(minX) + ", " + std::to_string(minY) + " x " +
|
||||||
|
std::to_string(maxX) + ", " + std::to_string(maxY);
|
||||||
QString region = QString::fromStdString(regionStr);
|
QString region = QString::fromStdString(regionStr);
|
||||||
|
|
||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
QVariant v = QVariant::fromValue(region);
|
QVariant v = QVariant::fromValue(region);
|
||||||
|
|
||||||
QString text = MakeScreenRegionSwitchName(sceneName, transitionName, minX, minY, maxX, maxY);
|
QString text = MakeScreenRegionSwitchName(sceneName, transitionName,
|
||||||
|
minX, minY, maxX, maxY);
|
||||||
|
|
||||||
int idx = ScreenRegionFindByData(region);
|
int idx = ScreenRegionFindByData(region);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->screenRegions);
|
new QListWidgetItem(text, ui->screenRegions);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->screenRegionSwitches.emplace_back(
|
switcher->screenRegionSwitches.emplace_back(
|
||||||
source, transition, minX, minY, maxX, maxY, regionStr);
|
source, transition, minX, minY, maxX, maxY, regionStr);
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->screenRegions->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->screenRegions->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
string curRegion = region.toUtf8().constData();
|
std::string curRegion = region.toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->screenRegionSwitches)
|
for (auto &s : switcher->screenRegionSwitches) {
|
||||||
{
|
if (s.regionStr == curRegion) {
|
||||||
if (s.regionStr == curRegion)
|
|
||||||
{
|
|
||||||
s.scene = source;
|
s.scene = source;
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->screenRegions->sortItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_screenRegionRemove_clicked()
|
void SceneSwitcher::on_screenRegionRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->screenRegions->currentItem();
|
QListWidgetItem *item = ui->screenRegions->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string region = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string region =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->screenRegionSwitches;
|
auto &switches = switcher->screenRegionSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.regionStr == region)
|
if (s.regionStr == region) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -122,19 +122,19 @@ void SceneSwitcher::on_screenRegions_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->screenRegions->item(idx);
|
QListWidgetItem *item = ui->screenRegions->item(idx);
|
||||||
|
|
||||||
QString region = item->data(Qt::UserRole).toString();
|
QString region = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->screenRegionSwitches)
|
for (auto &s : switcher->screenRegionSwitches) {
|
||||||
{
|
if (region.compare(s.regionStr.c_str()) == 0) {
|
||||||
if (region.compare(s.regionStr.c_str()) == 0)
|
std::string name = GetWeakSourceName(s.scene);
|
||||||
{
|
std::string transitionName =
|
||||||
string name = GetWeakSourceName(s.scene);
|
GetWeakSourceName(s.transition);
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
|
||||||
ui->screenRegionScenes->setCurrentText(name.c_str());
|
ui->screenRegionScenes->setCurrentText(name.c_str());
|
||||||
ui->screenRegionsTransitions->setCurrentText(transitionName.c_str());
|
ui->screenRegionsTransitions->setCurrentText(
|
||||||
|
transitionName.c_str());
|
||||||
ui->screenRegionMinX->setValue(s.minX);
|
ui->screenRegionMinX->setValue(s.minX);
|
||||||
ui->screenRegionMinY->setValue(s.minY);
|
ui->screenRegionMinY->setValue(s.minY);
|
||||||
ui->screenRegionMaxX->setValue(s.maxX);
|
ui->screenRegionMaxX->setValue(s.maxX);
|
||||||
@@ -144,18 +144,16 @@ void SceneSwitcher::on_screenRegions_currentRowChanged(int idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::ScreenRegionFindByData(const QString& region)
|
int SceneSwitcher::ScreenRegionFindByData(const QString ®ion)
|
||||||
{
|
{
|
||||||
int count = ui->screenRegions->count();
|
int count = ui->screenRegions->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->screenRegions->item(i);
|
||||||
QListWidgetItem* item = ui->screenRegions->item(i);
|
|
||||||
QString itemRegion = item->data(Qt::UserRole).toString();
|
QString itemRegion = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemRegion == region)
|
if (itemRegion == region) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -163,3 +161,124 @@ int SceneSwitcher::ScreenRegionFindByData(const QString& region)
|
|||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_screenRegionUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->screenRegions->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->screenRegions->insertItem(
|
||||||
|
index - 1, ui->screenRegions->takeItem(index));
|
||||||
|
ui->screenRegions->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->screenRegionSwitches.begin() + index,
|
||||||
|
switcher->screenRegionSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_screenRegionDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->screenRegions->currentRow();
|
||||||
|
if (index != -1 && index != ui->screenRegions->count() - 1) {
|
||||||
|
ui->screenRegions->insertItem(
|
||||||
|
index + 1, ui->screenRegions->takeItem(index));
|
||||||
|
ui->screenRegions->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->screenRegionSwitches.begin() + index,
|
||||||
|
switcher->screenRegionSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveScreenRegionSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *screenRegionArray = obs_data_array_create();
|
||||||
|
for (ScreenRegionSwitch &s : switcher->screenRegionSwitches) {
|
||||||
|
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);
|
||||||
|
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, "screenRegionScene",
|
||||||
|
sceneName);
|
||||||
|
obs_data_set_string(array_obj, "transition",
|
||||||
|
transitionName);
|
||||||
|
obs_data_set_int(array_obj, "minX", s.minX);
|
||||||
|
obs_data_set_int(array_obj, "minY", s.minY);
|
||||||
|
obs_data_set_int(array_obj, "maxX", s.maxX);
|
||||||
|
obs_data_set_int(array_obj, "maxY", s.maxY);
|
||||||
|
obs_data_set_string(array_obj, "screenRegionStr",
|
||||||
|
s.regionStr.c_str());
|
||||||
|
obs_data_array_push_back(screenRegionArray, array_obj);
|
||||||
|
obs_source_release(source);
|
||||||
|
obs_source_release(transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "screenRegion", screenRegionArray);
|
||||||
|
obs_data_array_release(screenRegionArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadScreenRegionSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->screenRegionSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *screenRegionArray =
|
||||||
|
obs_data_get_array(obj, "screenRegion");
|
||||||
|
size_t count = obs_data_array_count(screenRegionArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(screenRegionArray, i);
|
||||||
|
|
||||||
|
const char *scene =
|
||||||
|
obs_data_get_string(array_obj, "screenRegionScene");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
int minX = obs_data_get_int(array_obj, "minX");
|
||||||
|
int minY = obs_data_get_int(array_obj, "minY");
|
||||||
|
int maxX = obs_data_get_int(array_obj, "maxX");
|
||||||
|
int maxY = obs_data_get_int(array_obj, "maxY");
|
||||||
|
std::string regionStr =
|
||||||
|
obs_data_get_string(array_obj, "screenRegionStr");
|
||||||
|
|
||||||
|
switcher->screenRegionSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition), minX, minY, maxX,
|
||||||
|
maxY, regionStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(screenRegionArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupRegionTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->screenRegionScenes, false);
|
||||||
|
populateTransitionSelection(ui->screenRegionsTransitions);
|
||||||
|
|
||||||
|
for (auto &s : switcher->screenRegionSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeScreenRegionSwitchName(
|
||||||
|
sceneName.c_str(), transitionName.c_str(), s.minX,
|
||||||
|
s.minY, s.maxX, s.maxY);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->screenRegions);
|
||||||
|
item->setData(Qt::UserRole, s.regionStr.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// screen region cursor position
|
||||||
|
QTimer *screenRegionTimer = new QTimer(this);
|
||||||
|
connect(screenRegionTimer, SIGNAL(timeout()), this,
|
||||||
|
SLOT(updateScreenRegionCursorPos()));
|
||||||
|
screenRegionTimer->start(1000);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
static std::vector<std::pair<std::string, timeTrigger>> triggerTable = {
|
||||||
|
{"On any day", timeTrigger::ANY_DAY},
|
||||||
|
{"Mondays", timeTrigger::MONDAY},
|
||||||
|
{"Tuesdays", timeTrigger::TUSEDAY},
|
||||||
|
{"Wednesdays", timeTrigger::WEDNESDAY},
|
||||||
|
{"Thursdays", timeTrigger::THURSDAY},
|
||||||
|
{"Fridays", timeTrigger::FRIDAY},
|
||||||
|
{"Saturdays", timeTrigger::SATURDAY},
|
||||||
|
{"Sundays", timeTrigger::SUNDAY},
|
||||||
|
{"Atfer streaming/recording start", timeTrigger::LIVE}};
|
||||||
|
|
||||||
void SceneSwitcher::on_timeSwitches_currentRowChanged(int idx)
|
void SceneSwitcher::on_timeSwitches_currentRowChanged(int idx)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
@@ -11,13 +22,14 @@ void SceneSwitcher::on_timeSwitches_currentRowChanged(int idx)
|
|||||||
|
|
||||||
QString timeScenestr = item->data(Qt::UserRole).toString();
|
QString timeScenestr = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto &s : switcher->timeSwitches) {
|
for (auto &s : switcher->timeSwitches) {
|
||||||
if (timeScenestr.compare(s.timeSwitchStr.c_str()) == 0) {
|
if (timeScenestr.compare(s.timeSwitchStr.c_str()) == 0) {
|
||||||
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
||||||
QString transitionName =
|
QString transitionName =
|
||||||
GetWeakSourceName(s.transition).c_str();
|
GetWeakSourceName(s.transition).c_str();
|
||||||
ui->timeScenes->setCurrentText(sceneName);
|
ui->timeScenes->setCurrentText(sceneName);
|
||||||
|
ui->timeTrigger->setCurrentIndex(s.trigger);
|
||||||
ui->timeEdit->setTime(s.time);
|
ui->timeEdit->setTime(s.time);
|
||||||
ui->timeTransitions->setCurrentText(transitionName);
|
ui->timeTransitions->setCurrentText(transitionName);
|
||||||
break;
|
break;
|
||||||
@@ -25,9 +37,10 @@ void SceneSwitcher::on_timeSwitches_currentRowChanged(int idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::timeFindByData(const QString &timeStr)
|
int SceneSwitcher::timeFindByData(const timeTrigger &trigger, const QTime &time)
|
||||||
{
|
{
|
||||||
QRegExp rx("At " + timeStr + " switch to .*");
|
QRegExp rx(MakeTimeSwitchName(QStringLiteral(".*"),
|
||||||
|
QStringLiteral(".*"), trigger, time));
|
||||||
int count = ui->timeSwitches->count();
|
int count = ui->timeSwitches->count();
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@@ -53,16 +66,26 @@ void SceneSwitcher::on_timeAdd_clicked()
|
|||||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
|
|
||||||
QString text = MakeTimeSwitchName(sceneName, transitionName, time);
|
std::string triggerStr = ui->timeTrigger->currentText().toStdString();
|
||||||
|
auto it = std::find_if(
|
||||||
|
triggerTable.begin(), triggerTable.end(),
|
||||||
|
[&triggerStr](
|
||||||
|
const std::pair<std::string, timeTrigger> &element) {
|
||||||
|
return element.first == triggerStr;
|
||||||
|
});
|
||||||
|
timeTrigger trigger = it->second;
|
||||||
|
|
||||||
|
QString text =
|
||||||
|
MakeTimeSwitchName(sceneName, transitionName, trigger, time);
|
||||||
QVariant v = QVariant::fromValue(text);
|
QVariant v = QVariant::fromValue(text);
|
||||||
|
|
||||||
int idx = timeFindByData(time.toString());
|
int idx = timeFindByData(trigger, time);
|
||||||
|
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->timeSwitches.emplace_back(
|
switcher->timeSwitches.emplace_back(
|
||||||
source, transition, time,
|
source, transition, trigger, time,
|
||||||
(sceneName == QString(PREVIOUS_SCENE_NAME)),
|
(sceneName == QString(previous_scene_name)),
|
||||||
text.toUtf8().constData());
|
text.toUtf8().constData());
|
||||||
|
|
||||||
QListWidgetItem *item =
|
QListWidgetItem *item =
|
||||||
@@ -71,25 +94,23 @@ void SceneSwitcher::on_timeAdd_clicked()
|
|||||||
} else {
|
} else {
|
||||||
QListWidgetItem *item = ui->timeSwitches->item(idx);
|
QListWidgetItem *item = ui->timeSwitches->item(idx);
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto &s : switcher->timeSwitches) {
|
for (auto &s : switcher->timeSwitches) {
|
||||||
if (s.time == time) {
|
if (s.trigger == trigger && s.time == time) {
|
||||||
s.scene = source;
|
s.scene = source;
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.usePreviousScene =
|
s.usePreviousScene =
|
||||||
(sceneName ==
|
(sceneName ==
|
||||||
QString(PREVIOUS_SCENE_NAME));
|
QString(previous_scene_name));
|
||||||
s.timeSwitchStr =
|
s.timeSwitchStr =
|
||||||
text.toUtf8().constData();
|
text.toUtf8().constData();
|
||||||
;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->timeSwitches->sortItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,10 +120,11 @@ void SceneSwitcher::on_timeRemove_clicked()
|
|||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string text = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string text =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto &switches = switcher->timeSwitches;
|
auto &switches = switcher->timeSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
@@ -118,30 +140,192 @@ void SceneSwitcher::on_timeRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_timeUp_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->timeSwitches->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->timeSwitches->insertItem(index - 1,
|
||||||
|
ui->timeSwitches->takeItem(index));
|
||||||
|
ui->timeSwitches->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->timeSwitches.begin() + index,
|
||||||
|
switcher->timeSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_timeDown_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->timeSwitches->currentRow();
|
||||||
|
if (index != -1 && index != ui->timeSwitches->count() - 1) {
|
||||||
|
ui->timeSwitches->insertItem(index + 1,
|
||||||
|
ui->timeSwitches->takeItem(index));
|
||||||
|
ui->timeSwitches->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->timeSwitches.begin() + index,
|
||||||
|
switcher->timeSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool timesAreInInterval(QTime &time1, QTime &time2, int &interval)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
QTime validSwitchTimeWindow = time1.addMSecs(interval);
|
||||||
|
|
||||||
|
ret = time1 <= time2 && time2 <= validSwitchTimeWindow;
|
||||||
|
// check for overflow
|
||||||
|
if (!ret && validSwitchTimeWindow.msecsSinceStartOfDay() < interval) {
|
||||||
|
ret = time2 >= time1 || time2 <= validSwitchTimeWindow;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkLiveTime(TimeSwitch &s, QDateTime &start, int &interval)
|
||||||
|
{
|
||||||
|
if (start.isNull())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
QTime timePassed = QTime(0, 0).addMSecs(start.msecsTo(now));
|
||||||
|
|
||||||
|
return timesAreInInterval(s.time, timePassed, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkRegularTime(TimeSwitch &s, int &interval)
|
||||||
|
{
|
||||||
|
if (s.trigger != ANY_DAY &&
|
||||||
|
s.trigger != QDate::currentDate().dayOfWeek())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QTime now = QTime::currentTime();
|
||||||
|
|
||||||
|
return timesAreInInterval(s.time, now, interval);
|
||||||
|
}
|
||||||
|
|
||||||
void SwitcherData::checkTimeSwitch(bool &match, OBSWeakSource &scene,
|
void SwitcherData::checkTimeSwitch(bool &match, OBSWeakSource &scene,
|
||||||
OBSWeakSource &transition)
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
if (timeSwitches.size() == 0)
|
if (timeSwitches.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QTime now = QTime::currentTime();
|
|
||||||
|
|
||||||
for (TimeSwitch &s : timeSwitches) {
|
for (TimeSwitch &s : timeSwitches) {
|
||||||
|
if (s.trigger == LIVE)
|
||||||
QTime validSwitchTimeWindow = s.time.addMSecs(interval);
|
match = checkLiveTime(s, liveTime, interval);
|
||||||
|
else
|
||||||
match = s.time <= now && now <= validSwitchTimeWindow;
|
match = checkRegularTime(s, interval);
|
||||||
if (!match &&
|
|
||||||
validSwitchTimeWindow.msecsSinceStartOfDay() < interval) {
|
|
||||||
// check for overflow
|
|
||||||
match = now >= s.time || now <= validSwitchTimeWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
scene = (s.usePreviousScene) ? previousScene : s.scene;
|
scene = (s.usePreviousScene) ? previousScene : s.scene;
|
||||||
transition = s.transition;
|
transition = s.transition;
|
||||||
match = true;
|
match = true;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
blog(LOG_INFO,
|
||||||
|
"Advanced Scene Switcher time match");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitcherData::saveTimeSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
obs_data_array_t *timeArray = obs_data_array_create();
|
||||||
|
for (TimeSwitch &s : switcher->timeSwitches) {
|
||||||
|
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);
|
||||||
|
if ((s.usePreviousScene || sceneSource) && transition) {
|
||||||
|
const char *sceneName =
|
||||||
|
obs_source_get_name(sceneSource);
|
||||||
|
const char *transitionName =
|
||||||
|
obs_source_get_name(transition);
|
||||||
|
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, "trigger", s.trigger);
|
||||||
|
obs_data_set_string(
|
||||||
|
array_obj, "time",
|
||||||
|
s.time.toString().toStdString().c_str());
|
||||||
|
obs_data_array_push_back(timeArray, array_obj);
|
||||||
|
}
|
||||||
|
obs_source_release(sceneSource);
|
||||||
|
obs_source_release(transition);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "timeSwitches", timeArray);
|
||||||
|
obs_data_array_release(timeArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadTimeSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->timeSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *timeArray = obs_data_get_array(obj, "timeSwitches");
|
||||||
|
size_t count = obs_data_array_count(timeArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj = obs_data_array_item(timeArray, i);
|
||||||
|
|
||||||
|
const char *scene = obs_data_get_string(array_obj, "scene");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
timeTrigger trigger =
|
||||||
|
(timeTrigger)obs_data_get_int(array_obj, "trigger");
|
||||||
|
QTime time = QTime::fromString(
|
||||||
|
obs_data_get_string(array_obj, "time"));
|
||||||
|
|
||||||
|
std::string timeSwitchStr =
|
||||||
|
MakeTimeSwitchName(scene, transition, trigger, time)
|
||||||
|
.toUtf8()
|
||||||
|
.constData();
|
||||||
|
|
||||||
|
switcher->timeSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene),
|
||||||
|
GetWeakTransitionByName(transition), trigger, time,
|
||||||
|
(strcmp(scene, previous_scene_name) == 0),
|
||||||
|
timeSwitchStr);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(timeArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupTimeTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->timeScenes, true);
|
||||||
|
populateTransitionSelection(ui->timeTransitions);
|
||||||
|
|
||||||
|
for (auto t : triggerTable) {
|
||||||
|
ui->timeTrigger->addItem(t.first.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// assuming the streaming / recording entry is always last
|
||||||
|
ui->timeTrigger->setItemData(
|
||||||
|
(int)triggerTable.size() - 1,
|
||||||
|
"The time relative to the start of streaming / recording will be used",
|
||||||
|
Qt::ToolTipRole);
|
||||||
|
|
||||||
|
for (auto &s : switcher->timeSwitches) {
|
||||||
|
std::string sceneName = (s.usePreviousScene)
|
||||||
|
? previous_scene_name
|
||||||
|
: GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString listText = MakeTimeSwitchName(sceneName.c_str(),
|
||||||
|
transitionName.c_str(),
|
||||||
|
s.trigger, s.time);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(listText, ui->timeSwitches);
|
||||||
|
item->setData(Qt::UserRole, listText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
1002
src/volume-control.cpp
Normal file
1002
src/volume-control.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static bool GetWindowTitle(HWND window, string& title)
|
static bool GetWindowTitle(HWND window, string &title)
|
||||||
{
|
{
|
||||||
size_t len = (size_t)GetWindowTextLengthW(window);
|
size_t len = (size_t)GetWindowTextLengthW(window);
|
||||||
wstring wtitle;
|
wstring wtitle;
|
||||||
@@ -45,12 +45,13 @@ static bool WindowValid(HWND window)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetWindowList(vector<string>& windows)
|
void GetWindowList(vector<string> &windows)
|
||||||
{
|
{
|
||||||
|
windows.resize(0);
|
||||||
|
|
||||||
HWND window = GetWindow(GetDesktopWindow(), GW_CHILD);
|
HWND window = GetWindow(GetDesktopWindow(), GW_CHILD);
|
||||||
|
|
||||||
while (window)
|
while (window) {
|
||||||
{
|
|
||||||
string title;
|
string title;
|
||||||
if (WindowValid(window) && GetWindowTitle(window, title))
|
if (WindowValid(window) && GetWindowTitle(window, title))
|
||||||
windows.emplace_back(title);
|
windows.emplace_back(title);
|
||||||
@@ -58,7 +59,22 @@ void GetWindowList(vector<string>& windows)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCurrentWindowTitle(string& title)
|
// Overloaded
|
||||||
|
void GetWindowList(QStringList &windows)
|
||||||
|
{
|
||||||
|
windows.clear();
|
||||||
|
|
||||||
|
HWND window = GetWindow(GetDesktopWindow(), GW_CHILD);
|
||||||
|
|
||||||
|
while (window) {
|
||||||
|
string title;
|
||||||
|
if (WindowValid(window) && GetWindowTitle(window, title))
|
||||||
|
windows << QString::fromStdString(title);
|
||||||
|
window = GetNextWindow(window, GW_HWNDNEXT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetCurrentWindowTitle(string &title)
|
||||||
{
|
{
|
||||||
HWND window = GetForegroundWindow();
|
HWND window = GetForegroundWindow();
|
||||||
DWORD pid;
|
DWORD pid;
|
||||||
@@ -75,43 +91,63 @@ void GetCurrentWindowTitle(string& title)
|
|||||||
GetWindowTitle(window, title);
|
GetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<int, int> getCursorPos()
|
std::pair<int, int> getCursorPos()
|
||||||
{
|
{
|
||||||
pair<int, int> pos(0, 0);
|
std::pair<int, int> pos(0, 0);
|
||||||
POINT cursorPos;
|
POINT cursorPos;
|
||||||
if (GetPhysicalCursorPos(&cursorPos))
|
if (GetPhysicalCursorPos(&cursorPos)) {
|
||||||
{
|
|
||||||
pos.first = cursorPos.x;
|
pos.first = cursorPos.x;
|
||||||
pos.second = cursorPos.y;
|
pos.second = cursorPos.y;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFullscreen()
|
bool isFullscreen(std::string &title)
|
||||||
{
|
{
|
||||||
RECT appBounds;
|
RECT appBounds;
|
||||||
RECT rc;
|
MONITORINFO monitorInfo = {0};
|
||||||
GetWindowRect(GetDesktopWindow(), &rc);
|
|
||||||
HWND hwnd = GetForegroundWindow();
|
HWND hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
|
||||||
if (hwnd != GetDesktopWindow() && hwnd != GetShellWindow())
|
while (hwnd) {
|
||||||
{
|
string wtitle;
|
||||||
|
if (WindowValid(hwnd) && GetWindowTitle(hwnd, wtitle) &&
|
||||||
|
(wtitle == title ||
|
||||||
|
QString::fromStdString(wtitle).contains(QRegularExpression(
|
||||||
|
QString::fromStdString(title)))))
|
||||||
|
break;
|
||||||
|
|
||||||
|
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
monitorInfo.cbSize = sizeof(MONITORINFO);
|
||||||
|
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST),
|
||||||
|
&monitorInfo);
|
||||||
|
|
||||||
|
if (hwnd && hwnd != GetDesktopWindow() && hwnd != GetShellWindow()) {
|
||||||
|
if (IsZoomed(hwnd)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
GetWindowRect(hwnd, &appBounds);
|
GetWindowRect(hwnd, &appBounds);
|
||||||
if (rc.bottom == appBounds.bottom && rc.top == appBounds.top && rc.left == appBounds.left
|
if (monitorInfo.rcMonitor.bottom == appBounds.bottom &&
|
||||||
&& rc.right == appBounds.right)
|
monitorInfo.rcMonitor.top == appBounds.top &&
|
||||||
{
|
monitorInfo.rcMonitor.left == appBounds.left &&
|
||||||
|
monitorInfo.rcMonitor.right == appBounds.right) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetProcessList(QStringList &processes) {
|
void GetProcessList(QStringList &processes)
|
||||||
|
{
|
||||||
|
|
||||||
HANDLE procSnapshot;
|
HANDLE procSnapshot;
|
||||||
PROCESSENTRY32 procEntry;
|
PROCESSENTRY32 procEntry;
|
||||||
|
|
||||||
procSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
procSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
if (procSnapshot == INVALID_HANDLE_VALUE) return;
|
if (procSnapshot == INVALID_HANDLE_VALUE)
|
||||||
|
return;
|
||||||
|
|
||||||
procEntry.dwSize = sizeof(PROCESSENTRY32);
|
procEntry.dwSize = sizeof(PROCESSENTRY32);
|
||||||
|
|
||||||
@@ -122,30 +158,45 @@ void GetProcessList(QStringList &processes) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
QString tempexe = QString::fromWCharArray(procEntry.szExeFile);
|
QString tempexe = QString::fromWCharArray(procEntry.szExeFile);
|
||||||
if (tempexe == "System") continue;
|
if (tempexe == "System")
|
||||||
if (tempexe == "[System Process]") continue;
|
continue;
|
||||||
if (processes.contains(tempexe)) continue;
|
if (tempexe == "[System Process]")
|
||||||
|
continue;
|
||||||
|
if (processes.contains(tempexe))
|
||||||
|
continue;
|
||||||
processes.append(tempexe);
|
processes.append(tempexe);
|
||||||
} while (Process32Next(procSnapshot, &procEntry));
|
} while (Process32Next(procSnapshot, &procEntry));
|
||||||
|
|
||||||
CloseHandle(procSnapshot);
|
CloseHandle(procSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInFocus(const QString &exeToCheck) {
|
bool isInFocus(const QString &executable)
|
||||||
|
{
|
||||||
// only checks if the current foreground window is from the same executable,
|
// only checks if the current foreground window is from the same executable,
|
||||||
// may return true for incorrent not meant windows from a program
|
// may return true for any window from a program
|
||||||
HWND foregroundWindow = GetForegroundWindow();
|
HWND foregroundWindow = GetForegroundWindow();
|
||||||
DWORD processId = 0;
|
DWORD processId = 0;
|
||||||
GetWindowThreadProcessId(foregroundWindow, &processId);
|
GetWindowThreadProcessId(foregroundWindow, &processId);
|
||||||
|
|
||||||
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
|
HANDLE process = OpenProcess(
|
||||||
if (process == NULL) return false;
|
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
|
||||||
|
if (process == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
WCHAR executablePath[600];
|
WCHAR executablePath[600];
|
||||||
GetModuleFileNameEx(process, 0, executablePath, 600);
|
GetModuleFileNameEx(process, 0, executablePath, 600);
|
||||||
CloseHandle(process);
|
CloseHandle(process);
|
||||||
|
|
||||||
return exeToCheck == QString::fromWCharArray(executablePath).split(QRegExp("(/|\\\\)")).back();
|
QString file = QString::fromWCharArray(executablePath)
|
||||||
|
.split(QRegularExpression("(/|\\\\)"))
|
||||||
|
.back();
|
||||||
|
|
||||||
|
// True if executable switch equals current window
|
||||||
|
bool equals = (executable == file);
|
||||||
|
// True if executable switch matches current window
|
||||||
|
bool matches = file.contains(QRegularExpression(executable));
|
||||||
|
|
||||||
|
return (equals || matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLastInputTime()
|
int getLastInputTime()
|
||||||
|
|||||||
@@ -1,12 +1,71 @@
|
|||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
#include "headers/advanced-scene-switcher.hpp"
|
#include "headers/advanced-scene-switcher.hpp"
|
||||||
|
|
||||||
|
bool isRunning(std::string &title)
|
||||||
|
{
|
||||||
|
QStringList windows;
|
||||||
|
|
||||||
|
GetWindowList(windows);
|
||||||
|
// True if switch is running (direct)
|
||||||
|
bool equals = windows.contains(QString::fromStdString(title));
|
||||||
|
// True if switch is running (regex)
|
||||||
|
bool matches = (windows.indexOf(QRegularExpression(
|
||||||
|
QString::fromStdString(title))) != -1);
|
||||||
|
|
||||||
|
return (equals || matches);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFocused(std::string &title)
|
||||||
|
{
|
||||||
|
std::string current;
|
||||||
|
|
||||||
|
GetCurrentWindowTitle(current);
|
||||||
|
// True if switch equals current window
|
||||||
|
bool equals = (title == current);
|
||||||
|
// True if switch matches current window
|
||||||
|
bool matches = QString::fromStdString(current).contains(
|
||||||
|
QRegularExpression(QString::fromStdString(title)));
|
||||||
|
|
||||||
|
return (equals || matches);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_up_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->switches->currentRow();
|
||||||
|
if (index != -1 && index != 0) {
|
||||||
|
ui->switches->insertItem(index - 1,
|
||||||
|
ui->switches->takeItem(index));
|
||||||
|
ui->switches->setCurrentRow(index - 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->windowSwitches.begin() + index,
|
||||||
|
switcher->windowSwitches.begin() + index - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::on_down_clicked()
|
||||||
|
{
|
||||||
|
int index = ui->switches->currentRow();
|
||||||
|
if (index != -1 && index != ui->switches->count() - 1) {
|
||||||
|
ui->switches->insertItem(index + 1,
|
||||||
|
ui->switches->takeItem(index));
|
||||||
|
ui->switches->setCurrentRow(index + 1);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
|
|
||||||
|
iter_swap(switcher->windowSwitches.begin() + index,
|
||||||
|
switcher->windowSwitches.begin() + index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_add_clicked()
|
void SceneSwitcher::on_add_clicked()
|
||||||
{
|
{
|
||||||
QString sceneName = ui->scenes->currentText();
|
QString sceneName = ui->scenes->currentText();
|
||||||
QString windowName = ui->windows->currentText();
|
QString windowName = ui->windows->currentText();
|
||||||
QString transitionName = ui->transitions->currentText();
|
QString transitionName = ui->transitions->currentText();
|
||||||
bool fullscreen = ui->fullscreenCheckBox->isChecked();
|
bool fullscreen = ui->fullscreenCheckBox->isChecked();
|
||||||
|
bool focus = ui->focusCheckBox->isChecked();
|
||||||
|
|
||||||
if (windowName.isEmpty() || sceneName.isEmpty())
|
if (windowName.isEmpty() || sceneName.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -15,62 +74,57 @@ void SceneSwitcher::on_add_clicked()
|
|||||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||||
QVariant v = QVariant::fromValue(windowName);
|
QVariant v = QVariant::fromValue(windowName);
|
||||||
|
|
||||||
QString text = MakeSwitchName(sceneName, windowName, transitionName, fullscreen);
|
QString text = MakeSwitchName(sceneName, windowName, transitionName,
|
||||||
|
fullscreen, focus);
|
||||||
|
|
||||||
int idx = FindByData(windowName);
|
int idx = FindByData(windowName);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
{
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
lock_guard<mutex> lock(switcher->m);
|
|
||||||
switcher->windowSwitches.emplace_back(
|
switcher->windowSwitches.emplace_back(
|
||||||
source, windowName.toUtf8().constData(), transition, fullscreen);
|
source, windowName.toUtf8().constData(), transition,
|
||||||
|
fullscreen, focus);
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(text, ui->switches);
|
QListWidgetItem *item = new QListWidgetItem(text, ui->switches);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
}
|
} else {
|
||||||
else
|
QListWidgetItem *item = ui->switches->item(idx);
|
||||||
{
|
|
||||||
QListWidgetItem* item = ui->switches->item(idx);
|
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
|
|
||||||
string window = windowName.toUtf8().constData();
|
std::string window = windowName.toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->windowSwitches)
|
for (auto &s : switcher->windowSwitches) {
|
||||||
{
|
if (s.window == window) {
|
||||||
if (s.window == window)
|
|
||||||
{
|
|
||||||
s.scene = source;
|
s.scene = source;
|
||||||
s.transition = transition;
|
s.transition = transition;
|
||||||
s.fullscreen = fullscreen;
|
s.fullscreen = fullscreen;
|
||||||
|
s.focus = focus;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->switches->sortItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_remove_clicked()
|
void SceneSwitcher::on_remove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->switches->currentItem();
|
QListWidgetItem *item = ui->switches->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string window = item->data(Qt::UserRole).toString().toUtf8().constData();
|
std::string window =
|
||||||
|
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->windowSwitches;
|
auto &switches = switcher->windowSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s.window == window)
|
if (s.window == window) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -80,9 +134,6 @@ void SceneSwitcher::on_remove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SceneSwitcher::on_ignoreWindowsAdd_clicked()
|
void SceneSwitcher::on_ignoreWindowsAdd_clicked()
|
||||||
{
|
{
|
||||||
QString windowName = ui->ignoreWindowsWindows->currentText();
|
QString windowName = ui->ignoreWindowsWindows->currentText();
|
||||||
@@ -92,37 +143,36 @@ void SceneSwitcher::on_ignoreWindowsAdd_clicked()
|
|||||||
|
|
||||||
QVariant v = QVariant::fromValue(windowName);
|
QVariant v = QVariant::fromValue(windowName);
|
||||||
|
|
||||||
QList<QListWidgetItem*> items = ui->ignoreWindows->findItems(windowName, Qt::MatchExactly);
|
QList<QListWidgetItem *> items =
|
||||||
|
ui->ignoreWindows->findItems(windowName, Qt::MatchExactly);
|
||||||
|
|
||||||
if (items.size() == 0)
|
if (items.size() == 0) {
|
||||||
{
|
QListWidgetItem *item =
|
||||||
QListWidgetItem* item = new QListWidgetItem(windowName, ui->ignoreWindows);
|
new QListWidgetItem(windowName, ui->ignoreWindows);
|
||||||
item->setData(Qt::UserRole, v);
|
item->setData(Qt::UserRole, v);
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
switcher->ignoreWindowsSwitches.emplace_back(windowName.toUtf8().constData());
|
switcher->ignoreWindowsSwitches.emplace_back(
|
||||||
ui->ignoreWindows->sortItems();
|
windowName.toUtf8().constData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneSwitcher::on_ignoreWindowsRemove_clicked()
|
void SceneSwitcher::on_ignoreWindowsRemove_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->ignoreWindows->currentItem();
|
QListWidgetItem *item = ui->ignoreWindows->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString windowName = item->data(Qt::UserRole).toString();
|
QString windowName = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
auto& switches = switcher->ignoreWindowsSwitches;
|
auto &switches = switcher->ignoreWindowsSwitches;
|
||||||
|
|
||||||
for (auto it = switches.begin(); it != switches.end(); ++it)
|
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||||
{
|
auto &s = *it;
|
||||||
auto& s = *it;
|
|
||||||
|
|
||||||
if (s == windowName.toUtf8().constData())
|
if (s == windowName.toUtf8().constData()) {
|
||||||
{
|
|
||||||
switches.erase(it);
|
switches.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -132,18 +182,16 @@ void SceneSwitcher::on_ignoreWindowsRemove_clicked()
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SceneSwitcher::FindByData(const QString& window)
|
int SceneSwitcher::FindByData(const QString &window)
|
||||||
{
|
{
|
||||||
int count = ui->switches->count();
|
int count = ui->switches->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->switches->item(i);
|
||||||
QListWidgetItem* item = ui->switches->item(i);
|
|
||||||
QString itemWindow = item->data(Qt::UserRole).toString();
|
QString itemWindow = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemWindow == window)
|
if (itemWindow == window) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -152,21 +200,16 @@ int SceneSwitcher::FindByData(const QString& window)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SceneSwitcher::IgnoreWindowsFindByData(const QString &window)
|
||||||
|
|
||||||
|
|
||||||
int SceneSwitcher::IgnoreWindowsFindByData(const QString& window)
|
|
||||||
{
|
{
|
||||||
int count = ui->ignoreWindows->count();
|
int count = ui->ignoreWindows->count();
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
QListWidgetItem *item = ui->ignoreWindows->item(i);
|
||||||
QListWidgetItem* item = ui->ignoreWindows->item(i);
|
|
||||||
QString itemRegion = item->data(Qt::UserRole).toString();
|
QString itemRegion = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
if (itemRegion == window)
|
if (itemRegion == window) {
|
||||||
{
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -175,7 +218,6 @@ int SceneSwitcher::IgnoreWindowsFindByData(const QString& window)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneSwitcher::on_switches_currentRowChanged(int idx)
|
void SceneSwitcher::on_switches_currentRowChanged(int idx)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
@@ -183,27 +225,26 @@ void SceneSwitcher::on_switches_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->switches->item(idx);
|
QListWidgetItem *item = ui->switches->item(idx);
|
||||||
|
|
||||||
QString window = item->data(Qt::UserRole).toString();
|
QString window = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->windowSwitches)
|
for (auto &s : switcher->windowSwitches) {
|
||||||
{
|
if (window.compare(s.window.c_str()) == 0) {
|
||||||
if (window.compare(s.window.c_str()) == 0)
|
std::string name = GetWeakSourceName(s.scene);
|
||||||
{
|
std::string transitionName =
|
||||||
string name = GetWeakSourceName(s.scene);
|
GetWeakSourceName(s.transition);
|
||||||
string transitionName = GetWeakSourceName(s.transition);
|
|
||||||
ui->scenes->setCurrentText(name.c_str());
|
ui->scenes->setCurrentText(name.c_str());
|
||||||
ui->windows->setCurrentText(window);
|
ui->windows->setCurrentText(window);
|
||||||
ui->transitions->setCurrentText(transitionName.c_str());
|
ui->transitions->setCurrentText(transitionName.c_str());
|
||||||
ui->fullscreenCheckBox->setChecked(s.fullscreen);
|
ui->fullscreenCheckBox->setChecked(s.fullscreen);
|
||||||
|
ui->focusCheckBox->setChecked(s.focus);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneSwitcher::on_ignoreWindows_currentRowChanged(int idx)
|
void SceneSwitcher::on_ignoreWindows_currentRowChanged(int idx)
|
||||||
{
|
{
|
||||||
if (loading)
|
if (loading)
|
||||||
@@ -211,70 +252,181 @@ void SceneSwitcher::on_ignoreWindows_currentRowChanged(int idx)
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem* item = ui->ignoreWindows->item(idx);
|
QListWidgetItem *item = ui->ignoreWindows->item(idx);
|
||||||
|
|
||||||
QString window = item->data(Qt::UserRole).toString();
|
QString window = item->data(Qt::UserRole).toString();
|
||||||
|
|
||||||
lock_guard<mutex> lock(switcher->m);
|
std::lock_guard<std::mutex> lock(switcher->m);
|
||||||
for (auto& s : switcher->ignoreWindowsSwitches)
|
for (auto &s : switcher->ignoreWindowsSwitches) {
|
||||||
{
|
if (window.compare(s.c_str()) == 0) {
|
||||||
if (window.compare(s.c_str()) == 0)
|
|
||||||
{
|
|
||||||
ui->ignoreWindowsWindows->setCurrentText(s.c_str());
|
ui->ignoreWindowsWindows->setCurrentText(s.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitcherData::checkWindowTitleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
void SwitcherData::checkWindowTitleSwitch(bool &match, OBSWeakSource &scene,
|
||||||
|
OBSWeakSource &transition)
|
||||||
{
|
{
|
||||||
//check if title should be ignored
|
std::string title;
|
||||||
string title;
|
bool ignored = false;
|
||||||
|
|
||||||
|
// Check if current window is ignored
|
||||||
GetCurrentWindowTitle(title);
|
GetCurrentWindowTitle(title);
|
||||||
for (auto& window : ignoreWindowsSwitches)
|
for (auto &window : ignoreWindowsSwitches) {
|
||||||
{
|
// True if ignored switch equals current window
|
||||||
try
|
bool equals = (title == window);
|
||||||
{
|
// True if ignored switch matches current window
|
||||||
bool matches = regex_match(title, regex(window));
|
bool matches = QString::fromStdString(title).contains(
|
||||||
if (matches)
|
QRegularExpression(QString::fromStdString(window)));
|
||||||
{
|
|
||||||
title = lastTitle;
|
if (equals || matches) {
|
||||||
break;
|
ignored = true;
|
||||||
}
|
title = lastTitle;
|
||||||
}
|
|
||||||
catch (const regex_error&)
|
break;
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastTitle = title;
|
lastTitle = title;
|
||||||
|
|
||||||
//direct match
|
// Check for match
|
||||||
for (WindowSceneSwitch& s : windowSwitches)
|
for (WindowSceneSwitch &s : windowSwitches) {
|
||||||
{
|
// True if fullscreen is disabled OR current window is fullscreen
|
||||||
if (s.window == title)
|
bool fullscreen = (!s.fullscreen || isFullscreen(s.window));
|
||||||
{
|
// True if focus is disabled OR switch is focused
|
||||||
match = !s.fullscreen || (s.fullscreen && isFullscreen());
|
bool focus = (!s.focus || isFocused(s.window));
|
||||||
|
// True if current window is ignored AND switch equals OR matches last window
|
||||||
|
bool ignore =
|
||||||
|
(ignored &&
|
||||||
|
(title == s.window ||
|
||||||
|
QString::fromStdString(title).contains(
|
||||||
|
QRegularExpression(
|
||||||
|
QString::fromStdString(s.window)))));
|
||||||
|
|
||||||
|
if (isRunning(s.window) && (fullscreen && (focus || ignore))) {
|
||||||
|
match = true;
|
||||||
scene = s.scene;
|
scene = s.scene;
|
||||||
transition = s.transition;
|
transition = s.transition;
|
||||||
return;
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//regex match
|
}
|
||||||
for (WindowSceneSwitch& s : windowSwitches)
|
|
||||||
{
|
void SwitcherData::saveWindowTitleSwitches(obs_data_t *obj)
|
||||||
try
|
{
|
||||||
{
|
obs_data_array_t *windowTitleArray = obs_data_array_create();
|
||||||
bool matches = regex_match(title, regex(s.window));
|
for (WindowSceneSwitch &s : switcher->windowSwitches) {
|
||||||
if (matches)
|
obs_data_t *array_obj = obs_data_create();
|
||||||
{
|
|
||||||
match = !s.fullscreen || (s.fullscreen && isFullscreen());
|
obs_source_t *source = obs_weak_source_get_source(s.scene);
|
||||||
scene = s.scene;
|
obs_source_t *transition =
|
||||||
transition = s.transition;
|
obs_weak_source_get_source(s.transition);
|
||||||
}
|
if (source && transition) {
|
||||||
}
|
const char *sceneName = obs_source_get_name(source);
|
||||||
catch (const regex_error&)
|
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, "window_title",
|
||||||
|
s.window.c_str());
|
||||||
|
obs_data_set_bool(array_obj, "fullscreen",
|
||||||
|
s.fullscreen);
|
||||||
|
obs_data_set_bool(array_obj, "focus", s.focus);
|
||||||
|
obs_data_array_push_back(windowTitleArray, array_obj);
|
||||||
|
obs_source_release(source);
|
||||||
|
obs_source_release(transition);
|
||||||
}
|
}
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "switches", windowTitleArray);
|
||||||
|
obs_data_array_release(windowTitleArray);
|
||||||
|
|
||||||
|
obs_data_array_t *ignoreWindowsArray = obs_data_array_create();
|
||||||
|
for (std::string &window : switcher->ignoreWindowsSwitches) {
|
||||||
|
obs_data_t *array_obj = obs_data_create();
|
||||||
|
obs_data_set_string(array_obj, "ignoreWindow", window.c_str());
|
||||||
|
obs_data_array_push_back(ignoreWindowsArray, array_obj);
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_set_array(obj, "ignoreWindows", ignoreWindowsArray);
|
||||||
|
obs_data_array_release(ignoreWindowsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitcherData::loadWindowTitleSwitches(obs_data_t *obj)
|
||||||
|
{
|
||||||
|
switcher->windowSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *windowTitleArray =
|
||||||
|
obs_data_get_array(obj, "switches");
|
||||||
|
size_t count = obs_data_array_count(windowTitleArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(windowTitleArray, i);
|
||||||
|
|
||||||
|
const char *scene = obs_data_get_string(array_obj, "scene");
|
||||||
|
const char *transition =
|
||||||
|
obs_data_get_string(array_obj, "transition");
|
||||||
|
const char *window =
|
||||||
|
obs_data_get_string(array_obj, "window_title");
|
||||||
|
bool fullscreen = obs_data_get_bool(array_obj, "fullscreen");
|
||||||
|
bool focus = obs_data_get_bool(array_obj, "focus") ||
|
||||||
|
!obs_data_has_user_value(array_obj, "focus");
|
||||||
|
|
||||||
|
switcher->windowSwitches.emplace_back(
|
||||||
|
GetWeakSourceByName(scene), window,
|
||||||
|
GetWeakTransitionByName(transition), fullscreen, focus);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(windowTitleArray);
|
||||||
|
|
||||||
|
switcher->ignoreWindowsSwitches.clear();
|
||||||
|
|
||||||
|
obs_data_array_t *ignoreWindowsArray =
|
||||||
|
obs_data_get_array(obj, "ignoreWindows");
|
||||||
|
count = obs_data_array_count(ignoreWindowsArray);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
obs_data_t *array_obj =
|
||||||
|
obs_data_array_item(ignoreWindowsArray, i);
|
||||||
|
|
||||||
|
const char *window =
|
||||||
|
obs_data_get_string(array_obj, "ignoreWindow");
|
||||||
|
|
||||||
|
switcher->ignoreWindowsSwitches.emplace_back(window);
|
||||||
|
|
||||||
|
obs_data_release(array_obj);
|
||||||
|
}
|
||||||
|
obs_data_array_release(ignoreWindowsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneSwitcher::setupTitleTab()
|
||||||
|
{
|
||||||
|
populateSceneSelection(ui->scenes, false);
|
||||||
|
populateTransitionSelection(ui->transitions);
|
||||||
|
populateWindowSelection(ui->windows);
|
||||||
|
populateWindowSelection(ui->ignoreWindowsWindows);
|
||||||
|
|
||||||
|
for (auto &s : switcher->windowSwitches) {
|
||||||
|
std::string sceneName = GetWeakSourceName(s.scene);
|
||||||
|
std::string transitionName = GetWeakSourceName(s.transition);
|
||||||
|
QString text = MakeSwitchName(sceneName.c_str(),
|
||||||
|
s.window.c_str(),
|
||||||
|
transitionName.c_str(),
|
||||||
|
s.fullscreen, s.focus);
|
||||||
|
|
||||||
|
QListWidgetItem *item = new QListWidgetItem(text, ui->switches);
|
||||||
|
item->setData(Qt::UserRole, s.window.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &window : switcher->ignoreWindowsSwitches) {
|
||||||
|
QString text = QString::fromStdString(window);
|
||||||
|
|
||||||
|
QListWidgetItem *item =
|
||||||
|
new QListWidgetItem(text, ui->ignoreWindows);
|
||||||
|
item->setData(Qt::UserRole, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user